在BLE作为从设备开发时,发现MAC地址会随机变化,修改
system/bt/include/bt_target.h
#define BLE_LOCAL_PRIVACY_ENABLED FALSE
或者也可以在修改随机生成MAC的地方,写成固定的MAC地址
system/bt/stack/btm/btm_ble_multi_adv.cc
void RegisterAdvertiser(
base::Callback<void(uint8_t /* inst_id */, uint8_t /* status */)> cb)
override {
AdvertisingInstance* p_inst = &adv_inst[0];
for (uint8_t i = 0; i < inst_count; i++, p_inst++) {
if (p_inst->in_use) continue;
p_inst->in_use = true;
// set up periodic timer to update address.
if (BTM_BleLocalPrivacyEnabled()) {
p_inst->own_address_type = BLE_ADDR_RANDOM;
GenerateRpa(Bind(
[](AdvertisingInstance* p_inst,
base::Callback<void(uint8_t /* inst_id */, uint8_t /* status */)>
cb,
RawAddress bda) {
// p_inst->own_address = bda;
p_inst->own_address = *controller_get_interface()->get_address();
alarm_set_on_mloop(p_inst->adv_raddr_timer,
BTM_BLE_PRIVATE_ADDR_INT_MS,
btm_ble_adv_raddr_timer_timeout, p_inst);
cb.Run(p_inst->inst_id, BTM_BLE_MULTI_ADV_SUCCESS);
},
p_inst, cb));
} else {
p_inst->own_address_type = BLE_ADDR_PUBLIC;
p_inst->own_address = *controller_get_interface()->get_address();
cb.Run(p_inst->inst_id, BTM_BLE_MULTI_ADV_SUCCESS);
}
return;
}
LOG(INFO) << "no free advertiser instance";
cb.Run(0xFF, ADVERTISE_FAILED_TOO_MANY_ADVERTISERS);
}