From: Chris Manton Date: Thu, 31 Dec 2020 19:00:47 +0000 (-0800) Subject: Add tACL_CB::tACL_CONN::policy X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=afd4446918;p=android-x86%2Fsystem-bt.git Add tACL_CB::tACL_CONN::policy Provide space for link policy state Bug: 175344733 Test: cert Tag: #refactor Change-Id: I852b30c1d772c56ac765a975cda7a88adf57584c --- diff --git a/stack/Android.bp b/stack/Android.bp index 1355dd28e..0030e418b 100644 --- a/stack/Android.bp +++ b/stack/Android.bp @@ -102,6 +102,7 @@ cc_library_static { "bnep/bnep_main.cc", "bnep/bnep_utils.cc", "btm/ble_advertiser_hci_interface.cc", + "acl/acl.cc", "acl/btm_acl.cc", "acl/ble_acl.cc", "btm/ble_scanner_hci_interface.cc", @@ -658,6 +659,7 @@ cc_test { "system/bt/vnd/ble", ], srcs: crypto_toolbox_srcs + [ + "acl/acl.cc", "acl/ble_acl.cc", "acl/btm_acl.cc", "acl/btm_ble_connection_establishment.cc", diff --git a/stack/acl/acl.cc b/stack/acl/acl.cc new file mode 100644 index 000000000..8e3fb8e02 --- /dev/null +++ b/stack/acl/acl.cc @@ -0,0 +1,21 @@ +/* + * Copyright 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stack/acl/acl.h" + +tBTM_PM_MODE sACL_CONN::sPolicy::Mode() const { return this->mode.mode_; } + +hci_role_t sACL_CONN::sPolicy::Role() const { return this->role.role_; } diff --git a/stack/acl/acl.h b/stack/acl/acl.h index 996953c57..3e7b06bf5 100644 --- a/stack/acl/acl.h +++ b/stack/acl/acl.h @@ -112,6 +112,23 @@ inline std::string power_mode_state_text(tBTM_PM_STATE state) { } } +struct sACL_CONN; + +namespace bluetooth { +namespace shim { +tBTM_STATUS BTM_SetPowerMode(sACL_CONN& p_acl, const tBTM_PM_PWR_MD& new_mode); +tBTM_STATUS BTM_SetSsrParams(sACL_CONN& p_acl, uint16_t max_lat, + uint16_t min_rmt_to, uint16_t min_loc_to); +void btm_pm_on_mode_change(tHCI_STATUS status, uint16_t handle, + tHCI_MODE hci_mode, uint16_t interval); +void btm_pm_on_sniff_subrating(tHCI_STATUS status, uint16_t handle, + uint16_t maximum_transmit_latency, + uint16_t maximum_receive_latency, + uint16_t minimum_remote_timeout, + uint16_t minimum_local_timeout); +} // namespace shim +} // namespace bluetooth + typedef struct { uint16_t max_xmit_latency; uint16_t max_recv_latency; @@ -280,6 +297,62 @@ struct sACL_CONN { public: uint8_t sca; /* Sleep clock accuracy */ + + struct sPolicy { + tBTM_PM_MODE Mode() const; + struct { + bool IsPending() const { return pending_ != BTM_PM_MD_UNKNOWN; } + tBTM_PM_MODE Pending() const { return pending_; } + uint16_t Interval() const { return interval_; } + + private: + tBTM_PM_MODE mode_{BTM_PM_MD_ACTIVE}; + tBTM_PM_MODE pending_{BTM_PM_MD_UNKNOWN}; + uint16_t interval_{0}; + friend tBTM_STATUS bluetooth::shim::BTM_SetPowerMode( + sACL_CONN& p_acl, const tBTM_PM_PWR_MD& new_mode); + friend void bluetooth::shim::btm_pm_on_mode_change(tHCI_STATUS status, + uint16_t handle, + tHCI_MODE hci_mode, + uint16_t interval); + friend void sACL_CONN::Reset(); + friend tBTM_PM_MODE sACL_CONN::sPolicy::Mode() const; + } mode; + + hci_role_t Role() const; + struct { + unsigned RoleSwitchFailedCount() const { return role_switch_failed_cnt_; } + + private: + hci_role_t role_{HCI_ROLE_CENTRAL}; + unsigned role_switch_failed_cnt_{0}; + friend void sACL_CONN::Reset(); + friend tBTM_PM_MODE sACL_CONN::sPolicy::Role() const; + } role; + + struct { + bool IsPending() const { return pending_; } + + private: + bool pending_{false}; + friend tBTM_STATUS bluetooth::shim::BTM_SetSsrParams(sACL_CONN& p_acl, + uint16_t max_lat, + uint16_t min_rmt_to, + uint16_t min_loc_to); + friend void bluetooth::shim::btm_pm_on_sniff_subrating( + tHCI_STATUS status, uint16_t handle, + uint16_t maximum_transmit_latency, uint16_t maximum_receive_latency, + uint16_t minimum_remote_timeout, uint16_t minimum_local_timeout); + friend void sACL_CONN::Reset(); + } sniff_subrating; + + tLINK_POLICY Settings() const { return settings_; } + + private: + tLINK_POLICY settings_{kAllLinkPoliciesEnabled}; + friend void btm_set_link_policy(sACL_CONN* conn, tLINK_POLICY policy); + friend void sACL_CONN::Reset(); + } policy; }; typedef sACL_CONN tACL_CONN; diff --git a/stack/acl/btm_acl.cc b/stack/acl/btm_acl.cc index 4880c7798..0ce0fa421 100644 --- a/stack/acl/btm_acl.cc +++ b/stack/acl/btm_acl.cc @@ -128,8 +128,8 @@ static void btm_read_failed_contact_counter_timeout(void* data); static void btm_read_remote_ext_features(uint16_t handle, uint8_t page_number); static void btm_read_rssi_timeout(void* data); static void btm_read_tx_power_timeout(void* data); -static void btm_set_link_policy(tACL_CONN* conn, tLINK_POLICY policy); static void check_link_policy(tLINK_POLICY* settings); +void btm_set_link_policy(tACL_CONN* conn, tLINK_POLICY policy); namespace { void NotifyAclLinkUp(tACL_CONN& p_acl) { @@ -667,7 +667,7 @@ static void check_link_policy(tLINK_POLICY* settings) { } } -static void btm_set_link_policy(tACL_CONN* conn, tLINK_POLICY policy) { +void btm_set_link_policy(tACL_CONN* conn, tLINK_POLICY policy) { conn->link_policy = policy; check_link_policy(&conn->link_policy); if ((conn->link_policy & HCI_ENABLE_CENTRAL_PERIPHERAL_SWITCH) &&