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

Fix advertising timers

Right now, timers that rotate advertising address are started when stack
is starting and keep running all the time even when advertising is not
used. This patch fix that by starting the timer when advertising
instance is registered, and stopping it when it's unregistered.

Bug: 30622771
Change-Id: I638176bdc2f26c62d5ec3a56f6e81cd9c016df0b
parent 73679d01
......@@ -687,9 +687,6 @@ bool BTM_BleConfigPrivacy(bool privacy_mode)
p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_RANDOM;
btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low);
if (BTM_BleMaxMultiAdvInstanceCount() > 0)
btm_ble_multi_adv_enb_privacy(privacy_mode);
/* 4.2 controller only allow privacy 1.2 or mixed mode, resolvable private address in controller */
if (controller_get_interface()->supports_ble_privacy())
{
......
......@@ -460,8 +460,6 @@ extern void btm_ble_resolving_list_cleanup(void);
extern void btm_ble_multi_adv_init(void);
extern void* btm_ble_multi_adv_get_ref(uint8_t inst_id);
extern void btm_ble_multi_adv_cleanup(void);
extern void btm_ble_multi_adv_reenable(uint8_t inst_id);
extern void btm_ble_multi_adv_enb_privacy(bool enable);
extern char btm_ble_map_adv_tx_power(int tx_power_index);
extern void btm_ble_batchscan_init(void);
extern void btm_ble_batchscan_cleanup(void);
......
......@@ -313,15 +313,6 @@ void btm_ble_multi_adv_set_params(tBTM_BLE_MULTI_ADV_INST *p_inst,
param,
btm_ble_multi_adv_vsc_cmpl_cback);
p_inst->adv_evt = p_params->adv_type;
#if (BLE_PRIVACY_SPT == TRUE)
if (BTM_BleLocalPrivacyEnabled()) {
alarm_set_on_queue(p_inst->adv_raddr_timer,
BTM_BLE_PRIVATE_ADDR_INT_MS,
btm_ble_adv_raddr_timer_timeout, p_inst,
btu_general_alarm_queue);
}
#endif
btm_ble_multi_adv_enq_op_q(BTM_BLE_MULTI_ADV_SET_PARAM, p_inst->inst_id, cb);
}
......@@ -356,12 +347,6 @@ void btm_ble_multi_adv_write_rpa(tBTM_BLE_MULTI_ADV_INST *p_inst, BD_ADDR random
param,
btm_ble_multi_adv_vsc_cmpl_cback);
/* start a periodical timer to refresh random addr */
/* TODO: is the above comment correct - is the timer periodical? */
alarm_set_on_queue(p_inst->adv_raddr_timer,
BTM_BLE_PRIVATE_ADDR_INT_MS,
btm_ble_adv_raddr_timer_timeout, p_inst,
btu_general_alarm_queue);
btm_ble_multi_adv_enq_op_q(BTM_BLE_MULTI_ADV_SET_RANDOM_ADDR,
p_inst->inst_id, NULL);
}
......@@ -499,32 +484,6 @@ void btm_ble_multi_adv_reenable(uint8_t inst_id)
}
}
/*******************************************************************************
**
** Function btm_ble_multi_adv_enb_privacy
**
** Description This function enable/disable privacy setting in multi adv
**
** Parameters enable: enable or disable the adv instance.
**
** Returns none.
**
*******************************************************************************/
void btm_ble_multi_adv_enb_privacy(bool enable)
{
uint8_t i;
tBTM_BLE_MULTI_ADV_INST *p_inst = &btm_multi_adv_cb.p_adv_inst[0];
for (i = 0; i < BTM_BleMaxMultiAdvInstanceCount() - 1; i ++, p_inst++)
{
p_inst->in_use = false;
if (enable)
btm_ble_multi_adv_configure_rpa(p_inst);
else
alarm_cancel(p_inst->adv_raddr_timer);
}
}
void BTM_BleAdvRegister(tBTM_BLE_MULTI_ADV_CBACK *p_cback) {
tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
......@@ -539,6 +498,19 @@ void BTM_BleAdvRegister(tBTM_BLE_MULTI_ADV_CBACK *p_cback) {
for (uint8_t i = 0; i < BTM_BleMaxMultiAdvInstanceCount() - 1; i++, p_inst++) {
if (!p_inst->in_use) {
p_inst->in_use = TRUE;
#if (BLE_PRIVACY_SPT == TRUE)
// configure the address, and set up periodic timer to update it.
btm_ble_multi_adv_configure_rpa(p_inst);
if (BTM_BleLocalPrivacyEnabled()) {
alarm_set_on_queue(p_inst->adv_raddr_timer,
BTM_BLE_PRIVATE_ADDR_INT_MS,
btm_ble_adv_raddr_timer_timeout, p_inst,
btu_general_alarm_queue);
}
#endif
p_inst->p_cback = p_cback;
(p_inst->p_cback)(BTM_BLE_MULTI_ADV_REG_EVT,
p_inst->inst_id, BTM_BLE_MULTI_ADV_SUCCESS);
......@@ -756,7 +728,6 @@ void BTM_BleAdvUnregister(uint8_t inst_id)
//TODO(jpawlowski): only disable when enabled or enabling
btm_ble_enable_multi_adv(false, inst_id, NULL);
btm_ble_multi_adv_configure_rpa(p_inst);
alarm_cancel(p_inst->adv_raddr_timer);
p_inst->in_use = false;
}
......@@ -855,7 +826,7 @@ void btm_ble_multi_adv_init()
btm_multi_adv_cb.p_adv_inst[i].index = i;
btm_multi_adv_cb.p_adv_inst[i].inst_id = i + 1;
btm_multi_adv_cb.p_adv_inst[i].adv_raddr_timer =
alarm_new("btm_ble.adv_raddr_timer");
alarm_new_periodic("btm_ble.adv_raddr_timer");
}
BTM_RegisterForVSEvents(btm_ble_multi_adv_vse_cback, true);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment