• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <gtest/gtest.h>
18 
19 #include "model/controller/link_layer_controller.h"
20 
21 namespace rootcanal {
22 
23 using namespace bluetooth::hci;
24 
25 class LeCreateConnectionTest : public ::testing::Test {
26  public:
27   LeCreateConnectionTest() = default;
28   ~LeCreateConnectionTest() override = default;
29 
30  protected:
31   Address address_{0};
32   ControllerProperties properties_{};
33   LinkLayerController controller_{address_, properties_};
34 };
35 
TEST_F(LeCreateConnectionTest,ConnectUsingPublicAddress)36 TEST_F(LeCreateConnectionTest, ConnectUsingPublicAddress) {
37   ASSERT_EQ(controller_.LeCreateConnection(
38                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
39                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
40                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010,
41                 0x0c80, 0x0, 0x0),
42             ErrorCode::SUCCESS);
43 }
44 
TEST_F(LeCreateConnectionTest,ConnectUsingRandomAddress)45 TEST_F(LeCreateConnectionTest, ConnectUsingRandomAddress) {
46   ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
47   ASSERT_EQ(controller_.LeCreateConnection(
48                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
49                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
50                 OwnAddressType::RANDOM_DEVICE_ADDRESS, 0x100, 0x200, 0x010,
51                 0x0c80, 0x0, 0x0),
52             ErrorCode::SUCCESS);
53 }
54 
TEST_F(LeCreateConnectionTest,ConnectUsingResolvableAddress)55 TEST_F(LeCreateConnectionTest, ConnectUsingResolvableAddress) {
56   ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
57   ASSERT_EQ(controller_.LeCreateConnection(
58                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
59                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
60                 OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, 0x100, 0x200,
61                 0x010, 0x0c80, 0x0, 0x0),
62             ErrorCode::SUCCESS);
63 }
64 
TEST_F(LeCreateConnectionTest,InitiatingActive)65 TEST_F(LeCreateConnectionTest, InitiatingActive) {
66   ASSERT_EQ(controller_.LeCreateConnection(
67                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
68                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
69                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010,
70                 0x0c80, 0x0, 0x0),
71             ErrorCode::SUCCESS);
72 
73   ASSERT_EQ(controller_.LeCreateConnection(
74                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
75                 AddressWithType{Address{2}, AddressType::PUBLIC_DEVICE_ADDRESS},
76                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010,
77                 0x0c80, 0x0, 0x0),
78             ErrorCode::COMMAND_DISALLOWED);
79 }
80 
TEST_F(LeCreateConnectionTest,InvalidScanInterval)81 TEST_F(LeCreateConnectionTest, InvalidScanInterval) {
82   ASSERT_EQ(controller_.LeCreateConnection(
83                 0x3, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
84                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
85                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010,
86                 0x0c80, 0x0, 0x0),
87             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
88 
89   ASSERT_EQ(controller_.LeCreateConnection(
90                 0x4001, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
91                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
92                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010,
93                 0x0c80, 0x0, 0x0),
94             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
95 }
96 
TEST_F(LeCreateConnectionTest,InvalidScanWindow)97 TEST_F(LeCreateConnectionTest, InvalidScanWindow) {
98   ASSERT_EQ(controller_.LeCreateConnection(
99                 0x200, 0x3, InitiatorFilterPolicy::USE_PEER_ADDRESS,
100                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
101                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010,
102                 0x0c80, 0x0, 0x0),
103             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
104 
105   ASSERT_EQ(controller_.LeCreateConnection(
106                 0x200, 0x4001, InitiatorFilterPolicy::USE_PEER_ADDRESS,
107                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
108                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010,
109                 0x0c80, 0x0, 0x0),
110             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
111 
112   ASSERT_EQ(controller_.LeCreateConnection(
113                 0x100, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
114                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
115                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010,
116                 0x0c80, 0x0, 0x0),
117             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
118 }
119 
TEST_F(LeCreateConnectionTest,InvalidConnectionInterval)120 TEST_F(LeCreateConnectionTest, InvalidConnectionInterval) {
121   ASSERT_EQ(controller_.LeCreateConnection(
122                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
123                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
124                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x5, 0x200, 0x010,
125                 0x0c80, 0x0, 0x0),
126             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
127 
128   ASSERT_EQ(controller_.LeCreateConnection(
129                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
130                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
131                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x0c81, 0x200, 0x010,
132                 0x0c80, 0x0, 0x0),
133             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
134 
135   ASSERT_EQ(controller_.LeCreateConnection(
136                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
137                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
138                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x200, 0x5, 0x010,
139                 0x0c80, 0x0, 0x0),
140             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
141 
142   ASSERT_EQ(controller_.LeCreateConnection(
143                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
144                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
145                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x200, 0x0c81, 0x010,
146                 0x0c80, 0x0, 0x0),
147             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
148 
149   ASSERT_EQ(controller_.LeCreateConnection(
150                 0x4001, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
151                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
152                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x200, 0x100, 0x010,
153                 0x0c80, 0x0, 0x0),
154             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
155 }
156 
TEST_F(LeCreateConnectionTest,InvalidMaxLatency)157 TEST_F(LeCreateConnectionTest, InvalidMaxLatency) {
158   ASSERT_EQ(controller_.LeCreateConnection(
159                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
160                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
161                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x01f4,
162                 0x0c80, 0x0, 0x0),
163             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
164 }
165 
TEST_F(LeCreateConnectionTest,InvalidSupervisionTimeout)166 TEST_F(LeCreateConnectionTest, InvalidSupervisionTimeout) {
167   ASSERT_EQ(controller_.LeCreateConnection(
168                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
169                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
170                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x9,
171                 0x0, 0x0),
172             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
173 
174   ASSERT_EQ(controller_.LeCreateConnection(
175                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
176                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
177                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010,
178                 0x0c81, 0x0, 0x0),
179             ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
180 
181   ASSERT_EQ(controller_.LeCreateConnection(
182                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
183                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
184                 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x1f3,
185                 0x0c80, 0x0, 0x0),
186             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
187 }
188 
TEST_F(LeCreateConnectionTest,NoRandomAddress)189 TEST_F(LeCreateConnectionTest, NoRandomAddress) {
190   ASSERT_EQ(controller_.LeCreateConnection(
191                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
192                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
193                 OwnAddressType::RANDOM_DEVICE_ADDRESS, 0x100, 0x200, 0x010,
194                 0x0c80, 0x0, 0x0),
195             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
196 
197   ASSERT_EQ(controller_.LeCreateConnection(
198                 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
199                 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
200                 OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, 0x100, 0x200,
201                 0x010, 0x0c80, 0x0, 0x0),
202             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
203 }
204 
205 }  // namespace rootcanal
206