cyw43439
cyw43439 copied to clipboard
Can't change default BT Mac address
I've been running into the same issues mentioned in the GH isue below: https://github.com/raspberrypi/pico-sdk/issues/1323
Therefore, since all my picos have the same mac address, i want to change some of them
I found example code to change them from micropython. source: https://forums.raspberrypi.com/viewtopic.php?t=347650
Is there an accepted way to change the address that I just haven't been able to find, or should I try to implement the below and PR it?
// micropython's cywbt.c sets the BT MAC with cywbt_hci_cmd(0x3f, 0x0001, 6, buf), where buf contains the MAC
// We'll just build the entire raw HCI packet ourself here, adapting it to work with the Pico C++ SDK
uint8_t btMac[6] = { 0x43, 0x43, 0xA2, 0x01, 0x02, 0x03 };
int ogf = 0x3F;
int ocf = 0x0001;
uint8_t hciPacket[4 + 3 + sizeof(btMac)];
// 4 byte header, only need to set the last byte; see implementation in hci_transport_cyw43_send_packet()
memset(hciPacket, 0, sizeof(hciPacket));
hciPacket[3] = 0x01; // Packet Type: Command
hciPacket[4] = (uint8_t)ocf;
hciPacket[5] = (uint8_t)((ogf << 2) | (ocf >> 8));
hciPacket[6] = (uint8_t)sizeof(btMac); // Param Length
// Reverse the byte order
for(size_t i = 0; i < sizeof(btMac); ++i)
hciPacket[7 + i] = btMac[sizeof(btMac) - 1 - i];
cyw43_bluetooth_hci_write(hciPacket, sizeof(hciPacket));
}```