• 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 #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,
83                 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS,
84                 PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS,
85                 Address::kEmpty, AdvertisingFilterPolicy::LISTED_SCAN, 0x70,
86                 PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false),
87             ErrorCode::SUCCESS);
88   ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(
89                 true, {MakeEnabledSet(0, 0, 0)}),
90             ErrorCode::SUCCESS);
91 
92   ASSERT_EQ(controller_.LeClearResolvingList(), ErrorCode::COMMAND_DISALLOWED);
93 }
94 
95 }  // namespace rootcanal
96