bluetoothctl select-attribute fails when passed a UUID

Bug #2064544 reported by Garrett
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bluez Utilities
New
Undecided
Unassigned

Bug Description

The UUID-based attribute selection does not respect the connected device's MAC address.
If you have two identical bluetooth devices A, B with different MAC addresses, and you use bluetoothctl to first connect to A, disconnect, and then connect to B, then it will fail to select the proper UUID for any of unit B.

For illustration, assume the MAC address of device A is AA:AA:AA:AA:AA:AA, and device B is BB:BB:BB:BB:BB:BB, the following commands would produce the issue:
####################################################

service bluetooth restart

# Execute the following in bluetoothctl:
bluetoothctl
connect AA:AA:AA:AA:AA:AA
disconnect

connect BB:BB:BB:BB:BB:BB
menu gatt
attribute-info abd23151-81b1-4429-bc15-eb4869827151
Characteristic - Vendor specific
        UUID: abd23151-81b1-4429-bc15-eb4869827151
        Service: /org/bluez/hci0/dev_AA_AA_AA_AA_AA_AA/service003d <--------------- WRONG
                                     ^ -----------------------------------------------This is device A's!
        Flags: read
        MTU: 0x00f7

####################################################
See above? Even though I have connected to device B, and then selected its characteristic via UUID, the attribute returned is actually that of device A!

I can workaround the issue by using a different syntax:
#####################################################
bluetoothctl

connect AA:AA:AA:AA:AA:AA
disconnect

connect BB:BB:BB:BB:BB:BB
menu gatt
attribute-info /org/bluez/hci0/dev_BB_BB_BB_BB_BB_BB/service0042/char0043
Characteristic - Vendor specific
        UUID: abd23151-81b1-4429-bc15-eb4869827151
        Service: /org/bluez/hci0/dev_BB_BB_BB_BB_BB_BB/service0042
                                     ^-------------------------------------- Now it's correct.
        Flags: read
        MTU: 0x00f7
####################################################

Revision history for this message
Garrett (somebatteries) wrote :

$ bluetoothctl --version

bluetoothctl: 5.64

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy

affects: snappy-hwe-snaps → bluez
Revision history for this message
Garrett (somebatteries) wrote :

I downloaded source code and found that the issue is resolved with the following change:

static void cmd_select_attribute(int argc, char *argv[])
{
    GDBusProxy *proxy;

    if (!default_dev) {
        bt_shell_printf("No device connected\n");
        return bt_shell_noninteractive_quit(EXIT_FAILURE);
    }

    proxy = gatt_select_attribute(default_dev, argv[1]); //<----------- default_dev instead of default_attr
    if (proxy) {
        set_default_attribute(proxy);
        return bt_shell_noninteractive_quit(EXIT_SUCCESS);
    }

    return bt_shell_noninteractive_quit(EXIT_FAILURE);
}

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.