Skip to content

Commit

Permalink
drv/bluetooth_btstack: use static random address
Browse files Browse the repository at this point in the history
This changes the bluetooth driver to give the device a new random
address each time the bluetooth chip resets.

Issue: pybricks/support#600
  • Loading branch information
dlech committed Oct 20, 2022
1 parent a40c1ef commit 05a0036
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/pbio/drv/bluetooth/bluetooth_btstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,20 @@ void pbdrv_bluetooth_init(void) {
nordic_spp_service_server_init(nordic_spp_packet_handler);
}

static void handle_static_addr_random(void* arg) {
uint8_t *static_addr = arg;
// First two msb must be set to indicate static random address.
static_addr[0] |= 0xC0;
gap_random_address_set(static_addr);
}

void pbdrv_bluetooth_power_on(bool on) {
hci_power_control(on ? HCI_POWER_ON : HCI_POWER_OFF);

// generate a new static/random address each time we reset the Bluetooth chip
static btstack_crypto_random_t static_addr_random;
static uint8_t static_addr[6];
btstack_crypto_random_generate(&static_addr_random, static_addr, sizeof(static_addr), handle_static_addr_random, static_addr);
}

bool pbdrv_bluetooth_is_ready(void) {
Expand Down

0 comments on commit 05a0036

Please sign in to comment.