mirror of https://github.com/ARMmbed/mbed-os.git
BLE: Private address when initiating connection
parent
c39d03a531
commit
19d89366d7
|
@ -509,6 +509,12 @@ ble_error_t Gap::connect(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the random address to set, if not valid, report the error
|
||||||
|
const address_t *address = get_random_address(controller_operation_t::initiating);
|
||||||
|
if (!address) {
|
||||||
|
return BLE_ERROR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
ble_error_t ret = BLE_ERROR_INTERNAL_STACK_FAILURE;
|
ble_error_t ret = BLE_ERROR_INTERNAL_STACK_FAILURE;
|
||||||
|
|
||||||
if (is_extended_advertising_available() == false) {
|
if (is_extended_advertising_available() == false) {
|
||||||
|
@ -517,8 +523,16 @@ ble_error_t Gap::connect(
|
||||||
return BLE_ERROR_INVALID_PARAM;
|
return BLE_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_scan_enabled) {
|
||||||
|
if (!_active_sets.get(LEGACY_ADVERTISING_HANDLE) &&
|
||||||
|
!_pending_sets.get(LEGACY_ADVERTISING_HANDLE)
|
||||||
|
) {
|
||||||
|
_pal_gap.set_random_address(*address);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// ensure scan is stopped.
|
// ensure scan is stopped.
|
||||||
_pal_gap.scan_enable(false, false);
|
_pal_gap.scan_enable(false, false);
|
||||||
|
}
|
||||||
|
|
||||||
ret = _pal_gap.create_connection(
|
ret = _pal_gap.create_connection(
|
||||||
connectionParams.getScanIntervalArray()[0],
|
connectionParams.getScanIntervalArray()[0],
|
||||||
|
@ -534,9 +548,14 @@ ble_error_t Gap::connect(
|
||||||
connectionParams.getMinEventLengthArray()[0],
|
connectionParams.getMinEventLengthArray()[0],
|
||||||
connectionParams.getMaxConnectionIntervalArray()[0]
|
connectionParams.getMaxConnectionIntervalArray()[0]
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
// set the correct mac address before starting scanning.
|
||||||
|
if (!_scan_enabled) {
|
||||||
|
_pal_gap.set_random_address(*address);
|
||||||
} else {
|
} else {
|
||||||
// ensure scan is stopped.
|
// ensure scan is stopped.
|
||||||
_pal_gap.extended_scan_enable(false, duplicates_filter_t::DISABLE, 0, 0);
|
_pal_gap.extended_scan_enable(false, duplicates_filter_t::DISABLE, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// reduce the address type to public or random
|
// reduce the address type to public or random
|
||||||
peer_address_type_t adjusted_address_type(peer_address_type_t::PUBLIC);
|
peer_address_type_t adjusted_address_type(peer_address_type_t::PUBLIC);
|
||||||
|
|
Loading…
Reference in New Issue