Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b2598d98 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Small cleanup in GATT white list

* move local helper functions into local namespace
* reduce dependency on other modules

Bug: 112827989
Test: compilation
Change-Id: Ie4f783b00b5d0b77698412e09e35a5d11ed8f5f6
parent 7013f4c6
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright 2018 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 "types/raw_address.h"

/** Set BLE connectable mode to auto connect */
extern void BTM_BleStartAutoConn();

/** Adds the device into white list. Returns false if white list is full and
 * device can't be added, true otherwise. */
extern bool BTM_WhiteListAdd(const RawAddress& address);

/** Removes the device from white list */
extern void BTM_WhiteListRemove(const RawAddress& address);

/** Clear the whitelist, end any pending whitelist connections */
extern void BTM_WhiteListClear();
+2 −2
Original line number Diff line number Diff line
@@ -1117,7 +1117,7 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, bool is_direct,
    LOG(ERROR) << "Unsupported transport for background connection";
    return false;
  }
  return gatt_auto_connect_dev_add(p_reg, bd_addr);
  return gatt_auto_connect_dev_add(gatt_if, bd_addr);
}

/*******************************************************************************
@@ -1174,7 +1174,7 @@ bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& bd_addr,
  }
  // is not direct

  if (gatt_if) return gatt_auto_connect_dev_remove(p_reg, bd_addr);
  if (gatt_if) return gatt_auto_connect_dev_remove(p_reg->gatt_if, bd_addr);

  if (!gatt_clear_bg_dev_for_addr(bd_addr)) {
    LOG(ERROR)
+2 −2
Original line number Diff line number Diff line
@@ -467,9 +467,9 @@ extern tGATT_HDL_LIST_ELEM* gatt_find_hdl_buffer_by_handle(uint16_t handle);
extern tGATTS_SRV_CHG* gatt_add_srv_chg_clt(tGATTS_SRV_CHG* p_srv_chg);

/* for background connection */
extern bool gatt_auto_connect_dev_add(tGATT_REG* p_reg,
extern bool gatt_auto_connect_dev_add(tGATT_IF gatt_if,
                                      const RawAddress& bd_addr);
extern bool gatt_auto_connect_dev_remove(tGATT_REG* p_reg,
extern bool gatt_auto_connect_dev_remove(tGATT_IF gatt_if,
                                         const RawAddress& bd_addr);

/* server function */
+7 −7
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include "btm_int.h"
#include "gatt_api.h"
#include "gatt_int.h"
#include "gatt_utils_white_list.h"
#include "gattdefs.h"
#include "l2cdefs.h"
#include "sdp_api.h"
@@ -1303,22 +1304,21 @@ uint8_t* gatt_dbg_op_name(uint8_t op_code) {
 *
 * Returns          true if connection started; false otherwise.
 */
bool gatt_auto_connect_dev_add(tGATT_REG* p_reg, const RawAddress& bd_addr) {
bool gatt_auto_connect_dev_add(tGATT_IF gatt_if, const RawAddress& bd_addr) {
  VLOG(1) << __func__;

  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE);

  bool ret = gatt_add_bg_dev_list(p_reg, bd_addr);
  bool ret = gatt_add_bg_dev_list(gatt_if, bd_addr);
  if (ret && p_tcb != NULL) {
    /* if a connected device, update the link holding number */
    gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
    gatt_update_app_use_link_flag(gatt_if, p_tcb, true, true);
  }
  return ret;
}

/** Remove the application interface for the specified background device */
bool gatt_auto_connect_dev_remove(tGATT_REG* p_reg, const RawAddress& bd_addr) {
bool gatt_auto_connect_dev_remove(tGATT_IF gatt_if, const RawAddress& bd_addr) {
  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE);
  if (p_tcb) gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, false, false);
  return gatt_remove_bg_dev_from_list(p_reg, bd_addr);
  if (p_tcb) gatt_update_app_use_link_flag(gatt_if, p_tcb, false, false);
  return gatt_remove_bg_dev_from_list(gatt_if, bd_addr);
}
+17 −16
Original line number Diff line number Diff line
@@ -19,9 +19,24 @@
#include "gatt_utils_white_list.h"

#include <base/logging.h>
#include <list>

#include "stack/btm/btm_ble_bgconn.h"

namespace {
std::list<tGATT_BG_CONN_DEV> bgconn_dev;

std::list<tGATT_BG_CONN_DEV>::iterator gatt_find_bg_dev_it(
    const RawAddress& remote_bda) {
  auto& list = bgconn_dev;
  for (auto it = list.begin(); it != list.end(); it++) {
    if (it->remote_bda == remote_bda) {
      return it;
    }
  }
  return list.end();
}

}  // namespace

/** Returns true if this is one of the background devices for the application,
@@ -41,22 +56,9 @@ tGATT_BG_CONN_DEV* gatt_find_bg_dev(const RawAddress& remote_bda) {
  return nullptr;
}

std::list<tGATT_BG_CONN_DEV>::iterator gatt_find_bg_dev_it(
    const RawAddress& remote_bda) {
  auto& list = bgconn_dev;
  for (auto it = list.begin(); it != list.end(); it++) {
    if (it->remote_bda == remote_bda) {
      return it;
    }
  }
  return list.end();
}

/** Add a device from the background connection list.  Returns true if device
 * added to the list, or already in list, false otherwise */
bool gatt_add_bg_dev_list(tGATT_REG* p_reg, const RawAddress& bd_addr) {
  tGATT_IF gatt_if = p_reg->gatt_if;

bool gatt_add_bg_dev_list(tGATT_IF gatt_if, const RawAddress& bd_addr) {
  tGATT_BG_CONN_DEV* p_dev = gatt_find_bg_dev(bd_addr);
  if (p_dev) {
    // device already in the whitelist, just add interested app to the list
@@ -91,8 +93,7 @@ uint8_t gatt_clear_bg_dev_for_addr(const RawAddress& bd_addr) {
/** Remove device from the background connection device list or listening to
 * advertising list.  Returns true if device was on the list and was succesfully
 * removed */
bool gatt_remove_bg_dev_from_list(tGATT_REG* p_reg, const RawAddress& bd_addr) {
  tGATT_IF gatt_if = p_reg->gatt_if;
bool gatt_remove_bg_dev_from_list(tGATT_IF gatt_if, const RawAddress& bd_addr) {
  auto dev_it = gatt_find_bg_dev_it(bd_addr);
  if (dev_it == bgconn_dev.end()) return false;

Loading