• 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 LeSetExtendedScanParametersTest : public ::testing::Test {
26  public:
27   LeSetExtendedScanParametersTest() = default;
28   ~LeSetExtendedScanParametersTest() override = default;
29 
30  protected:
31   Address address_{0};
32   ControllerProperties properties_{};
33   LinkLayerController controller_{address_, properties_};
34 };
35 
MakeScanningPhyParameters(LeScanType scan_type,uint16_t scan_interval,uint16_t scan_window)36 static ScanningPhyParameters MakeScanningPhyParameters(LeScanType scan_type,
37                                                        uint16_t scan_interval,
38                                                        uint16_t scan_window) {
39   ScanningPhyParameters parameters;
40   parameters.le_scan_type_ = scan_type;
41   parameters.le_scan_interval_ = scan_interval;
42   parameters.le_scan_window_ = scan_window;
43   return parameters;
44 }
45 
TEST_F(LeSetExtendedScanParametersTest,Success)46 TEST_F(LeSetExtendedScanParametersTest, Success) {
47   ASSERT_EQ(controller_.LeSetExtendedScanParameters(
48                 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
49                 LeScanningFilterPolicy::ACCEPT_ALL, 0x5,
50                 {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200),
51                  MakeScanningPhyParameters(LeScanType::ACTIVE, 0x2000, 0x200)}),
52             ErrorCode::SUCCESS);
53 }
54 
TEST_F(LeSetExtendedScanParametersTest,ScanningActive)55 TEST_F(LeSetExtendedScanParametersTest, ScanningActive) {
56   ASSERT_EQ(controller_.LeSetExtendedScanParameters(
57                 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
58                 LeScanningFilterPolicy::ACCEPT_ALL, 0x5,
59                 {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200),
60                  MakeScanningPhyParameters(LeScanType::ACTIVE, 0x2000, 0x200)}),
61             ErrorCode::SUCCESS);
62   ASSERT_EQ(controller_.LeSetExtendedScanEnable(
63                 true, FilterDuplicates::DISABLED, 0, 0),
64             ErrorCode::SUCCESS);
65 
66   ASSERT_EQ(controller_.LeSetExtendedScanParameters(
67                 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
68                 LeScanningFilterPolicy::ACCEPT_ALL, 0x5,
69                 {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200),
70                  MakeScanningPhyParameters(LeScanType::ACTIVE, 0x2000, 0x200)}),
71             ErrorCode::COMMAND_DISALLOWED);
72 }
73 
TEST_F(LeSetExtendedScanParametersTest,ReservedPhy)74 TEST_F(LeSetExtendedScanParametersTest, ReservedPhy) {
75   ASSERT_EQ(
76       controller_.LeSetExtendedScanParameters(
77           OwnAddressType::PUBLIC_DEVICE_ADDRESS,
78           LeScanningFilterPolicy::ACCEPT_ALL, 0x80,
79           {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}),
80       ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
81 }
82 
TEST_F(LeSetExtendedScanParametersTest,InvalidPhyParameters)83 TEST_F(LeSetExtendedScanParametersTest, InvalidPhyParameters) {
84   ASSERT_EQ(controller_.LeSetExtendedScanParameters(
85                 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
86                 LeScanningFilterPolicy::ACCEPT_ALL, 0x1, {}),
87             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
88 
89   ASSERT_EQ(
90       controller_.LeSetExtendedScanParameters(
91           OwnAddressType::PUBLIC_DEVICE_ADDRESS,
92           LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
93           {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200),
94            MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}),
95       ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
96 }
97 
TEST_F(LeSetExtendedScanParametersTest,InvalidScanInterval)98 TEST_F(LeSetExtendedScanParametersTest, InvalidScanInterval) {
99   ASSERT_EQ(controller_.LeSetExtendedScanParameters(
100                 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
101                 LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
102                 {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x0, 0x200)}),
103             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
104 }
105 
TEST_F(LeSetExtendedScanParametersTest,InvalidScanWindow)106 TEST_F(LeSetExtendedScanParametersTest, InvalidScanWindow) {
107   ASSERT_EQ(controller_.LeSetExtendedScanParameters(
108                 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
109                 LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
110                 {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x0)}),
111             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
112 
113   ASSERT_EQ(
114       controller_.LeSetExtendedScanParameters(
115           OwnAddressType::PUBLIC_DEVICE_ADDRESS,
116           LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
117           {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x2001)}),
118       ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
119 }
120 
121 }  // namespace rootcanal
122