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 LeSetRandomAddressTest : public ::testing::Test {
27 public:
28 LeSetRandomAddressTest() = default;
29 ~LeSetRandomAddressTest() override = default;
30
31 protected:
32 Address address_{0};
33 ControllerProperties properties_{};
34 LinkLayerController controller_{address_, properties_};
35 };
36
TEST_F(LeSetRandomAddressTest,Success)37 TEST_F(LeSetRandomAddressTest, Success) {
38 ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
39 }
40
TEST_F(LeSetRandomAddressTest,ScanningActive)41 TEST_F(LeSetRandomAddressTest, ScanningActive) {
42 controller_.LeSetScanEnable(true, false);
43 ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::COMMAND_DISALLOWED);
44 }
45
TEST_F(LeSetRandomAddressTest,LegacyAdvertisingActive)46 TEST_F(LeSetRandomAddressTest, LegacyAdvertisingActive) {
47 ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS);
48 ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::COMMAND_DISALLOWED);
49 }
50
TEST_F(LeSetRandomAddressTest,ExtendedAdvertisingActive)51 TEST_F(LeSetRandomAddressTest, ExtendedAdvertisingActive) {
52 ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters(
53 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7,
54 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
55 PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty,
56 AdvertisingFilterPolicy::LISTED_SCAN, 0x70, PrimaryPhyType::LE_1M, 0,
57 SecondaryPhyType::LE_2M, 0x0, false),
58 ErrorCode::SUCCESS);
59 ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}),
60 ErrorCode::SUCCESS);
61
62 // The Random Address is not used for extended advertising,
63 // each set has its own address configured using the command
64 // LE_Set_Advertising_Set_Random_Address.
65 // It is allowed to modify the Random Address while extended advertising
66 // is active.
67 ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
68 }
69
70 } // namespace rootcanal
71