Search code examples
linuxubuntubluetoothubuntu-16.04bluez

Is there a way to find out which Bluetooth device is plugged into which USB port?


I'm using two Bluetooth adaptors with BlueZ, both are the same device but with different types of antenna, is there any method to find out which usb port the identifier on BlueZ (hci0/hci1) is referring to?

I can discover the MAC address of the device through hcitool dev, so if there was a way to discover which USB port the adaptor with that MAC address was connected to, that would also solve my problem.

As both the adaptors are the same model, lsusb does not provide any identifying information I can use.

Using Ubuntu 16.04. I am looking for a solution in any form, whether it is a shell command or java/C/python/etc.


Solution

  • This answer should point you in the right direction, though doesn't give you a complete solution.

    You should be able to use the contents of the "sys" filesystem, under /sys/class/bluetooth:

    $ ls -lA /sys/class/bluetooth/
    total 0
    lrwxrwxrwx  1 root root 0 Dec  8 09:35 hci0 -> ../../devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/bluetooth/hci0
    lrwxrwxrwx  1 root root 0 Dec  8 09:35 hci1 -> ../../devices/platform/soc/3f201000.serial/tty/ttyAMA0/hci1
    

    That's from my Raspberry Pi, with a builtin adapter on the /dev/ttyAMA0 UART interface, and an added Bluetooth adapter on USB. The information in the symlink target technically tells you which physical port the adapter is plugged into.

    If you're not familiar with the convention for USB device numbering (which forms a tree of nodes, since a port can have a USB hub with multiple additional ports, etc), look under /sys/bus/usb/devices, and match that up with the "lsusb" output and you should figure it out. In my case, "lsusb" shows that adapter as "Bus 001 Device 004: ID 0a5c:21e8 Broadcom Corp. BCM20702A0 Bluetooth 4.0", which if I recall corresponds to the "1-3" stuff in the /sys/class/bluetooth path (where unfortunately it appears the bus value uses index origin 1, while the device number uses index origin 0 so the 4 turns into a 3 there).

    If you experiment with moving your USB adapter around to different physical ports, you should be able to work out the pattern.