Skip to content

Commit

Permalink
fix BLE ADV random address configuration (project-chip#32657)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinez-silabs authored Mar 21, 2024
1 parent 31f73a7 commit 7f14133
Showing 1 changed file with 21 additions and 29 deletions.
50 changes: 21 additions & 29 deletions src/platform/silabs/efr32/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,29 +476,33 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
ReturnErrorOnFailure(EncodeAdditionalDataTlv());
#endif

if (0xff != advertising_set_handle)
if (advertising_set_handle == 0xff)
{
sl_bt_advertiser_delete_set(advertising_set_handle);
advertising_set_handle = 0xff;
}

ret = sl_bt_advertiser_create_set(&advertising_set_handle);
if (ret != SL_STATUS_OK)
{
err = MapBLEError(ret);
ChipLogError(DeviceLayer, "sl_bt_advertiser_create_set() failed: %s", ErrorStr(err));
ExitNow();
ret = sl_bt_advertiser_create_set(&advertising_set_handle);
VerifyOrExit(ret == SL_STATUS_OK, {
err = MapBLEError(ret);
ChipLogError(DeviceLayer, "sl_bt_advertiser_create_set() failed: %s", ErrorStr(err));
});

bd_addr randomizedAddr = {};
ret = sl_bt_advertiser_set_random_address(advertising_set_handle, sl_bt_gap_random_resolvable_address, randomizedAddr,
&randomizedAddr);
VerifyOrExit(ret == SL_STATUS_OK, {
err = MapBLEError(ret);
ChipLogError(DeviceLayer, "sl_bt_advertiser_set_random_address() failed: %s", ErrorStr(err));
});
ChipLogDetail(DeviceLayer, "BLE Resolvable private random address %02X:%02X:%02X:%02X:%02X:%02X", randomizedAddr.addr[5],
randomizedAddr.addr[4], randomizedAddr.addr[3], randomizedAddr.addr[2], randomizedAddr.addr[1],
randomizedAddr.addr[0]);
}

ret = sl_bt_legacy_advertiser_set_data(advertising_set_handle, sl_bt_advertiser_advertising_data_packet, index,
(uint8_t *) advData);

if (ret != SL_STATUS_OK)
{
VerifyOrExit(ret == SL_STATUS_OK, {
err = MapBLEError(ret);
ChipLogError(DeviceLayer, "sl_bt_legacy_advertiser_set_data() - Advertising Data failed: %s", ErrorStr(err));
ExitNow();
}
});

index = 0;

Expand All @@ -515,12 +519,10 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
ret = sl_bt_legacy_advertiser_set_data(advertising_set_handle, sl_bt_advertiser_scan_response_packet, index,
(uint8_t *) responseData);

if (ret != SL_STATUS_OK)
{
VerifyOrExit(ret == SL_STATUS_OK, {
err = MapBLEError(ret);
ChipLogError(DeviceLayer, "sl_bt_legacy_advertiser_set_data() - Scan Response failed: %s", ErrorStr(err));
ExitNow();
}
});

err = MapBLEError(ret);

Expand Down Expand Up @@ -548,11 +550,6 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
ChipLogDetail(DeviceLayer, "Start BLE advertisement");
}

const uint8_t kResolvableRandomAddrType = 2; // Private resolvable random address type
bd_addr unusedBdAddr; // We can ignore this field when setting random address.
sl_bt_advertiser_set_random_address(advertising_set_handle, kResolvableRandomAddrType, unusedBdAddr, &unusedBdAddr);
(void) unusedBdAddr;

err = ConfigureAdvertisingData();
SuccessOrExit(err);

Expand Down Expand Up @@ -582,11 +579,6 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
#endif
}

// TODO(#32274): Explain why we cannot have interval_min == interval_max.
if (interval_min == interval_max)
{
++interval_max;
}
ChipLogProgress(DeviceLayer, "Starting advertising with interval_min=%u, intverval_max=%u (units of 625us)",
static_cast<unsigned>(interval_min), static_cast<unsigned>(interval_max));
ret = sl_bt_advertiser_set_timing(advertising_set_handle, interval_min, interval_max, 0, 0);
Expand Down

0 comments on commit 7f14133

Please sign in to comment.