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 #include "test_helpers.h"
21
22 namespace rootcanal {
23
24 using namespace bluetooth::hci;
25
26 class LeClearResolvingListTest : public ::testing::Test {
27 public:
LeClearResolvingListTest()28 LeClearResolvingListTest() {
29 // Reduce the size of the resolving list to simplify testing.
30 properties_.le_resolving_list_size = 2;
31 }
32
33 ~LeClearResolvingListTest() override = default;
34
35 protected:
36 Address address_{0};
37 ControllerProperties properties_{};
38 LinkLayerController controller_{address_, properties_};
39 };
40
TEST_F(LeClearResolvingListTest,Success)41 TEST_F(LeClearResolvingListTest, Success) {
42 ASSERT_EQ(controller_.LeAddDeviceToResolvingList(
43 PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1},
44 std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}),
45 ErrorCode::SUCCESS);
46
47 ASSERT_EQ(controller_.LeClearResolvingList(), ErrorCode::SUCCESS);
48 }
49
TEST_F(LeClearResolvingListTest,ScanningActive)50 TEST_F(LeClearResolvingListTest, ScanningActive) {
51 ASSERT_EQ(controller_.LeAddDeviceToResolvingList(
52 PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1},
53 std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}),
54 ErrorCode::SUCCESS);
55
56 ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS);
57 controller_.LeSetScanEnable(true, false);
58
59 ASSERT_EQ(controller_.LeClearResolvingList(), ErrorCode::COMMAND_DISALLOWED);
60 }
61
TEST_F(LeClearResolvingListTest,LegacyAdvertisingActive)62 TEST_F(LeClearResolvingListTest, LegacyAdvertisingActive) {
63 ASSERT_EQ(controller_.LeAddDeviceToResolvingList(
64 PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1},
65 std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}),
66 ErrorCode::SUCCESS);
67
68 ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS);
69 ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS);
70
71 ASSERT_EQ(controller_.LeClearResolvingList(), ErrorCode::COMMAND_DISALLOWED);
72 }
73
TEST_F(LeClearResolvingListTest,ExtendedAdvertisingActive)74 TEST_F(LeClearResolvingListTest, ExtendedAdvertisingActive) {
75 ASSERT_EQ(controller_.LeAddDeviceToResolvingList(
76 PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1},
77 std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}),
78 ErrorCode::SUCCESS);
79
80 ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS);
81 ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters(
82 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7,
83 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
84 PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty,
85 AdvertisingFilterPolicy::LISTED_SCAN, 0x70, PrimaryPhyType::LE_1M, 0,
86 SecondaryPhyType::LE_2M, 0x0, false),
87 ErrorCode::SUCCESS);
88 ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}),
89 ErrorCode::SUCCESS);
90
91 ASSERT_EQ(controller_.LeClearResolvingList(), ErrorCode::COMMAND_DISALLOWED);
92 }
93
94 } // namespace rootcanal
95