gap: set random address for both legacy advertising and extended advertising

This commit is contained in:
Matthias Ringwald 2023-03-06 12:35:34 +01:00
parent 64f9dabab0
commit 9ce6dfa163
2 changed files with 26 additions and 13 deletions

View File

@ -5686,7 +5686,8 @@ static bool hci_run_general_gap_le(void){
#endif
// check if own address changes
bool random_address_change = (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_ADDRESS) != 0;
uint8_t address_change_mask = LE_ADVERTISEMENT_TASKS_SET_ADDRESS | LE_ADVERTISEMENT_TASKS_SET_ADDRESS_SET_0;
bool random_address_change = (hci_stack->le_advertisements_todo & address_change_mask) != 0;
// check if whitelist needs modification
bool whitelist_modification_pending = false;
@ -5949,14 +5950,7 @@ static bool hci_run_general_gap_le(void){
if (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_ADDRESS){
hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_ADDRESS;
#ifdef ENABLE_LE_EXTENDED_ADVERTISING
if (hci_extended_advertising_supported()) {
hci_send_cmd(&hci_le_set_advertising_set_random_address, 0, hci_stack->le_random_address);
} else
#endif
{
hci_send_cmd(&hci_le_set_random_address, hci_stack->le_random_address);
}
hci_send_cmd(&hci_le_set_random_address, hci_stack->le_random_address);
#ifdef ENABLE_LE_SET_ADV_PARAMS_ON_RANDOM_ADDRESS_CHANGE
// workaround: on some Controllers, address in advertisements is updated only after next dv params set
hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_PARAMS;
@ -6032,6 +6026,15 @@ static bool hci_run_general_gap_le(void){
return true;
}
#ifdef ENABLE_LE_EXTENDED_ADVERTISING
// assumption: only set if extended advertising is supported
if ((hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_ADDRESS_SET_0) != 0){
hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_ADDRESS_SET_0;
hci_send_cmd(&hci_le_set_advertising_set_random_address, 0, hci_stack->le_random_address);
return true;
}
#endif
if (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_ADV_DATA){
hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_ADV_DATA;
uint8_t adv_data_clean[31];
@ -8358,6 +8361,15 @@ void hci_le_random_address_set(const bd_addr_t random_address){
memcpy(hci_stack->le_random_address, random_address, 6);
hci_stack->le_random_address_set = true;
hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_ADDRESS;
#ifdef ENABLE_LE_EXTENDED_ADVERTISING
if (hci_extended_advertising_supported()){
// force advertising set creation for LE Set Advertising Set Random Address
if ((hci_stack->le_advertisements_state & LE_ADVERTISEMENT_STATE_PARAMS_SET) == 0){
hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_PARAMS;
}
hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_ADDRESS_SET_0;
}
#endif
hci_run();
}

View File

@ -886,10 +886,11 @@ enum {
LE_ADVERTISEMENT_TASKS_SET_ADV_DATA = 1 << 0,
LE_ADVERTISEMENT_TASKS_SET_SCAN_DATA = 1 << 1,
LE_ADVERTISEMENT_TASKS_SET_PARAMS = 1 << 2,
LE_ADVERTISEMENT_TASKS_SET_ADDRESS = 1 << 3,
LE_ADVERTISEMENT_TASKS_SET_PERIODIC_PARAMS = 1 << 4,
LE_ADVERTISEMENT_TASKS_SET_PERIODIC_DATA = 1 << 5,
LE_ADVERTISEMENT_TASKS_REMOVE_SET = 1 << 6,
LE_ADVERTISEMENT_TASKS_SET_PERIODIC_PARAMS = 1 << 3,
LE_ADVERTISEMENT_TASKS_SET_PERIODIC_DATA = 1 << 4,
LE_ADVERTISEMENT_TASKS_REMOVE_SET = 1 << 5,
LE_ADVERTISEMENT_TASKS_SET_ADDRESS = 1 << 6,
LE_ADVERTISEMENT_TASKS_SET_ADDRESS_SET_0 = 1 << 7,
};
enum {