initiating_phys);
else {
if (transport == BT_TRANSPORT_LE)
- status = gatt_update_auto_connect_dev(gatt_if, true, bd_addr);
+ status = gatt_auto_connect_dev_add(p_reg, bd_addr);
else {
LOG(ERROR) << "Unsupported transport for background connection";
}
bool is_direct) {
LOG(INFO) << __func__ << ": gatt_if=" << +gatt_if;
- if (gatt_if && !gatt_get_regcb(gatt_if)) {
- LOG(ERROR) << "gatt_if=" << +gatt_if << " is not registered";
- return false;
+ tGATT_REG* p_reg;
+ if (gatt_if) {
+ p_reg = gatt_get_regcb(gatt_if);
+ if (!p_reg) {
+ LOG(ERROR) << "gatt_if=" << +gatt_if << " is not registered";
+ return false;
+ }
}
if (is_direct) {
}
// is not direct
- if (gatt_if) return gatt_remove_bg_dev_for_app(gatt_if, bd_addr);
+ if (gatt_if) return gatt_auto_connect_dev_remove(p_reg, bd_addr);
if (!gatt_clear_bg_dev_for_addr(bd_addr)) {
LOG(ERROR)
extern tGATTS_SRV_CHG* gatt_add_srv_chg_clt(tGATTS_SRV_CHG* p_srv_chg);
/* for background connection */
-extern bool gatt_update_auto_connect_dev(tGATT_IF gatt_if, bool add,
+extern bool gatt_auto_connect_dev_add(tGATT_REG* p_reg,
+ const RawAddress& bd_addr);
+extern bool gatt_auto_connect_dev_remove(tGATT_REG* p_reg,
const RawAddress& bd_addr);
extern bool gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV* p_dev, tGATT_IF gatt_if);
-extern bool gatt_remove_bg_dev_for_app(tGATT_IF gatt_if,
- const RawAddress& bd_addr);
extern uint8_t gatt_clear_bg_dev_for_addr(const RawAddress& bd_addr);
extern tGATT_BG_CONN_DEV* gatt_find_bg_dev(const RawAddress& remote_bda);
extern void gatt_deregister_bgdev_list(tGATT_IF gatt_if);
return true;
}
-/** Remove the application interface for the specified background device */
-bool gatt_remove_bg_dev_for_app(tGATT_IF gatt_if, const RawAddress& bd_addr) {
- tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE);
- bool status;
-
- if (p_tcb) gatt_update_app_use_link_flag(gatt_if, p_tcb, false, false);
- status = gatt_update_auto_connect_dev(gatt_if, false, bd_addr);
- return status;
-}
-
/** Removes all registrations for background connection for given device.
* Returns true if anything was removed, false otherwise */
uint8_t gatt_clear_bg_dev_for_addr(const RawAddress& bd_addr) {
gatt_cb.bgconn_dev.erase(dev_it);
return true;
}
+
/** deregister all related back ground connetion device. */
void gatt_deregister_bgdev_list(tGATT_IF gatt_if) {
auto it = gatt_cb.bgconn_dev.begin();
}
}
-/*******************************************************************************
- *
- * Function gatt_reset_bgdev_list
- *
- * Description reset bg device list
- *
- * Returns pointer to the device record
- *
- ******************************************************************************/
+/** reset bg device list */
void gatt_reset_bgdev_list(void) { gatt_cb.bgconn_dev.clear(); }
-/*******************************************************************************
- *
- * Function gatt_update_auto_connect_dev
- *
- * Description This function add or remove a device for background
- * connection procedure.
+
+/**
+ * This function add a device for background connection procedure.
*
- * Parameters gatt_if: Application ID.
- * add: add peer device
+ * Parameters p_reg: application record,
* bd_addr: peer device address.
*
* Returns true if connection started; false otherwise.
- *
- ******************************************************************************/
-bool gatt_update_auto_connect_dev(tGATT_IF gatt_if, bool add,
- const RawAddress& bd_addr) {
- tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, BT_TRANSPORT_LE);
-
+ */
+bool gatt_auto_connect_dev_add(tGATT_REG* p_reg, const RawAddress& bd_addr) {
VLOG(1) << __func__;
- /* Make sure app is registered */
- tGATT_REG* p_reg = gatt_get_regcb(gatt_if);
- if (!p_reg) {
- LOG(ERROR) << __func__ << " gatt_if is not registered " << +gatt_if;
- return false;
- }
- if (!add) return gatt_remove_bg_dev_from_list(p_reg, bd_addr);
+ 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);
if (ret && p_tcb != NULL) {
/* if a connected device, update the link holding number */
- gatt_update_app_use_link_flag(gatt_if, p_tcb, true, true);
+ gatt_update_app_use_link_flag(p_reg->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) {
+ 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);
+}