Comment 12 for bug 989817

Revision history for this message
TJ (tj) wrote :

To permanently change the adapter device name using a bluez tool we have to use DBus to set the name using org.bluez.Adaptor.SetProperty which is handled by set_name(), which results in a call to adapter_set_name() which in turn calls write_local_name().

dbus-send --print-reply --system --dest=org.bluez /org/bluez/$(pidof bluetoothd)/hci0 org.bluez.Adapter.SetProperty string:'Name' variant:string:'adapter_name'

$ dbus-send --print-reply --system --dest=org.bluez /org/bluez/$(pidof bluetoothd)/hci0 org.bluez.Adapter.SetProperty string:'Name' variant:string:'adapter_name'
method return sender=:1.164 -> dest=:1.189 reply_serial=2

$ cat /var/lib/bluetooth/00\:1F\:E1\:E0\:EB\:96/config
name adapter_name
pairable yes
class 0x6e0100
onmode discoverable
mode discoverable

'bluetoothd' reads "/etc/bluetooth/main.conf" where we have "Name = %h-%d" which should be expanded to "<host>-<adapter_id>".

This is passed to the 'adaptername' plugin function adaptername_probe() which calls read_pretty_host_name(). This function looks for a systemd-specific text file "/etc/machine-info" and if found reads the file then looks for a line with the prefix "PRETTY_HOSTNAME=" and uses the name assigned there.

If no name has been set at this point read_local_name() is called to get the name from "/var/lib/bluetooth/$MAC/config". If no name is obtained from that file expand_name(,,"%h-%d",) is called and a name created from the machine hostname and bluetooth adapter id, e.g. "hostname-0".

This is later written out to "/var/lib/bluetooth/$MAC/config".

It appears to me that "ubuntu-0" is created during installation from a liveISO environment where the default machine name is always "ubuntu". Bluetooth starts in the live environment and assigns the "ubuntu-0" name to the adapter. Later, when bluetoothd is installed in the target the configuration file is probably copied over, or otherwise generated based on the live environment.

Once there is a name entry in "/var/lib/bluetooth/$MAC/config" the bluetoothd adaptername plugin will not generate a new name.

---- debug with "name adapter_name" setting in /var/lib/bluetooth/$MAC/config ----
bluetoothd[11119]: src/main.c:parse_config() name=%h-%d
bluetoothd[11119]: src/plugin.c:add_plugin() Loading adaptername plugin
bluetoothd[11119]: plugins/hciops.c:read_local_name_complete() hci0 status 0
bluetoothd[11119]: plugins/hciops.c:read_local_name_complete() Got name for hci0
bluetoothd[11119]: plugins/adaptername.c:adaptername_probe() Setting name 'adapter_name' for device 'hci0'
bluetoothd[11119]: plugins/hciops.c:hciops_set_name() hci0, name adapter_name

-- debug with no "name" setting in /var/lib/bluetooth/$MAC/config ----
bluetoothd[11425]: src/main.c:parse_config() name=%h-%d
bluetoothd[11425]: src/plugin.c:add_plugin() Loading adaptername plugin
bluetoothd[11425]: plugins/hciops.c:read_local_name_complete() hci0 status 0
bluetoothd[11425]: plugins/hciops.c:read_local_name_complete() Got name for hci0
bluetoothd[11425]: plugins/adaptername.c:adaptername_probe() Setting name 'XPSm1530-0' for device 'hci0'
bluetoothd[11425]: plugins/hciops.c:hciops_set_name() hci0, name XPSm1530-0