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}),
44 ErrorCode::COMMAND_DISALLOWED);
45 }
46
TEST_F(LeSetRandomAddressTest,LegacyAdvertisingActive)47 TEST_F(LeSetRandomAddressTest, LegacyAdvertisingActive) {
48 ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS);
49 ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}),
50 ErrorCode::COMMAND_DISALLOWED);
51 }
52
TEST_F(LeSetRandomAddressTest,ExtendedAdvertisingActive)53 TEST_F(LeSetRandomAddressTest, ExtendedAdvertisingActive) {
54 ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters(
55 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800,
56 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS,
57 PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS,
58 Address::kEmpty, AdvertisingFilterPolicy::LISTED_SCAN, 0x70,
59 PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false),
60 ErrorCode::SUCCESS);
61 ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(
62 true, {MakeEnabledSet(0, 0, 0)}),
63 ErrorCode::SUCCESS);
64
65 // The Random Address is not used for extended advertising,
66 // each set has its own address configured using the command
67 // LE_Set_Advertising_Set_Random_Address.
68 // It is allowed to modify the Random Address while extended advertising
69 // is active.
70 ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
71 }
72
73 } // namespace rootcanal
74