RPi 4 internal BT chip hci assignment changes when USB Bluetooth device connected at boot

Hello,
I am working on a project that accesses Bluetooth hardware by its hci number. My Raspberry Pis have an internal bluetooth chip, which comes up as hci0:

root@2165xxx:/app# hciconfig -a
hci0:   Type: Primary  Bus: UART
        BD Address: DC:A6:32:C3:xx:xx  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING 
       [...]
        Manufacturer: Cypress Semiconductor Corporation (305)

if I plug in a USB bluetooth dongle after the Pi has booted, it shows up as hci1:

root@2165xxx:/app# hciconfig -a
hci1:   Type: Primary  Bus: USB
        BD Address: 00:01:95:62:xx:xx  ACL MTU: 310:10  SCO MTU: 64:8
        [...]
        Manufacturer: Cambridge Silicon Radio (10)

hci0:   Type: Primary  Bus: UART
        BD Address: DC:A6:32:C3:xx:xx  ACL MTU: 1021:8  SCO MTU: 64:1
        [...]
        Manufacturer: Cypress Semiconductor Corporation (305)

BUT, if the Pi boots with the USB bluetooth dongle already connected, the hci assignment seems to switch so that the USB device is hci0 and the internal chip is hci1:

root@2165xxx:/app# hciconfig -a
hci1:   Type: Primary  Bus: UART
        BD Address: DC:A6:32:C3:xx:xx  ACL MTU: 1021:8  SCO MTU: 64:1
        [...]
        Manufacturer: Cypress Semiconductor Corporation (305)

hci0:   Type: Primary  Bus: USB
        BD Address: 00:01:95:62:xx:xx  ACL MTU: 310:10  SCO MTU: 64:8
        [...]
        Manufacturer: Cambridge Silicon Radio (10)

this assignment persists even if the USB device is disconnected, until the next reboot (and then it depends if the USB device is plugged in or not).

Is this a bug in the kernel somewhere? It seems like the internal hardware should always be hci0, and then externally-connected devices should get assigned starting at hci1.

I could probably work around this issue if there was a way for me to a) list connected BT chips from inside my app and b) enable/disable each from inside my app.

Hello @verigo_tommy
I get similar results here using a BT dongle on both balenaOS and Ubuntu 20.04. I’ve flagged your message for the attention of our Devices Team to see if they have any comments on this behaviour or a potential workaround.

1 Like

Hi, something you could try is to create a udev rule that identifies the dongle and creates an identification symlink that you can then use, something like /dev/hci-internal and /dev/hci-external for example. These will be linked to the correct hciX device at each boot.
Another solution would be for your application to identify the internal interface by MAC address and then use hcitool to disambiguate.