• 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 #include <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 
19 #include <cstdint>
20 #include <deque>
21 
22 #include "common/init_flags.h"
23 #include "osi/include/log.h"
24 #include "stack/acl/acl.h"
25 #include "stack/btm/btm_int_types.h"
26 #include "stack/btm/security_device_record.h"
27 #include "stack/include/acl_api.h"
28 #include "stack/include/acl_hci_link_interface.h"
29 #include "stack/include/hci_error_code.h"
30 #include "test/common/mock_functions.h"
31 #include "test/mock/mock_main_shim_acl_api.h"
32 #include "types/ble_address_with_type.h"
33 #include "types/hci_role.h"
34 #include "types/raw_address.h"
35 
36 tBTM_CB btm_cb;
37 
LogMsg(uint32_t trace_set_mask,const char * fmt_str,...)38 void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...) {}
39 
40 namespace {
41 const char* test_flags[] = {
42     "INIT_logging_debug_enabled_for_all=true",
43     nullptr,
44 };
45 
46 const RawAddress kRawAddress = RawAddress({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
47 }  // namespace
48 
49 namespace bluetooth {
50 namespace testing {
51 
52 std::set<const RawAddress> copy_of_connected_with_both_public_and_random_set();
53 
54 }  // namespace testing
55 }  // namespace bluetooth
56 
BTM_update_version_info(const RawAddress & bd_addr,const remote_version_info & remote_version_info)57 void BTM_update_version_info(const RawAddress& bd_addr,
58                              const remote_version_info& remote_version_info) {}
59 
btm_sec_role_changed(tHCI_STATUS hci_status,const RawAddress & bd_addr,tHCI_ROLE new_role)60 void btm_sec_role_changed(tHCI_STATUS hci_status, const RawAddress& bd_addr,
61                           tHCI_ROLE new_role) {}
62 
63 class StackAclTest : public testing::Test {
64  protected:
SetUp()65   void SetUp() override {
66     mock_function_count_map.clear();
67     bluetooth::common::InitFlags::Load(test_flags);
68   }
TearDown()69   void TearDown() override {}
70 
71   tBTM_SEC_DEV_REC device_record_;
72 };
73 
TEST_F(StackAclTest,nop)74 TEST_F(StackAclTest, nop) {}
75 
TEST_F(StackAclTest,acl_process_extended_features)76 TEST_F(StackAclTest, acl_process_extended_features) {
77   const uint16_t hci_handle = 0x123;
78   const tBT_TRANSPORT transport = BT_TRANSPORT_LE;
79   const tHCI_ROLE link_role = HCI_ROLE_CENTRAL;
80 
81   btm_acl_created(kRawAddress, hci_handle, link_role, transport);
82   tACL_CONN* p_acl = btm_acl_for_bda(kRawAddress, transport);
83   ASSERT_NE(nullptr, p_acl);
84 
85   // Handle typical case
86   {
87     const uint8_t max_page = 3;
88     memset((void*)p_acl->peer_lmp_feature_valid, 0,
89            HCI_EXT_FEATURES_PAGE_MAX + 1);
90     acl_process_extended_features(hci_handle, 1, max_page, 0xf123456789abcde);
91     acl_process_extended_features(hci_handle, 2, max_page, 0xef123456789abcd);
92     acl_process_extended_features(hci_handle, 3, max_page, 0xdef123456789abc);
93 
94     /* page 0 is the standard feature set */
95     ASSERT_FALSE(p_acl->peer_lmp_feature_valid[0]);
96     ASSERT_TRUE(p_acl->peer_lmp_feature_valid[1]);
97     ASSERT_TRUE(p_acl->peer_lmp_feature_valid[2]);
98     ASSERT_TRUE(p_acl->peer_lmp_feature_valid[3]);
99   }
100 
101   // Handle extreme case
102   {
103     const uint8_t max_page = 255;
104     memset((void*)p_acl->peer_lmp_feature_valid, 0,
105            HCI_EXT_FEATURES_PAGE_MAX + 1);
106     for (int i = 1; i < HCI_EXT_FEATURES_PAGE_MAX + 1; i++) {
107       acl_process_extended_features(hci_handle, static_cast<uint8_t>(i),
108                                     max_page, 0x123456789abcdef);
109     }
110     /* page 0 is the standard feature set */
111     ASSERT_FALSE(p_acl->peer_lmp_feature_valid[0]);
112     ASSERT_TRUE(p_acl->peer_lmp_feature_valid[1]);
113     ASSERT_TRUE(p_acl->peer_lmp_feature_valid[2]);
114     ASSERT_TRUE(p_acl->peer_lmp_feature_valid[3]);
115   }
116 
117   // Handle case where device returns max page of zero
118   {
119     memset((void*)p_acl->peer_lmp_feature_valid, 0,
120            HCI_EXT_FEATURES_PAGE_MAX + 1);
121     acl_process_extended_features(hci_handle, 1, 0, 0xdef123456789abc);
122     ASSERT_FALSE(p_acl->peer_lmp_feature_valid[0]);
123     ASSERT_TRUE(p_acl->peer_lmp_feature_valid[1]);
124     ASSERT_FALSE(p_acl->peer_lmp_feature_valid[2]);
125     ASSERT_FALSE(p_acl->peer_lmp_feature_valid[3]);
126   }
127 
128   btm_acl_removed(hci_handle);
129 }
130