How is the btmgmt command used to set PHY?

388 Views Asked by At

When I run the command: btmgmt phy LE2MTX LE2MRX

It returns: Could not set PHY Configuration with status 0x0d (Invalid Parameters)

btmon shows:

@ MGMT Open: btmgmt                                                                     
@ MGMT Command: Set PHY Configuration (0x0045) plen 4                                                       
        Selected PHYs: 0x1800
          LE 2M TX
          LE 2M RX
@ MGMT Event: Command Status (0x0002) plen 3                                                                
      Set PHY Configuration (0x0045)
        Status: Invalid Parameters (0x0d)
@ MGMT Close: btmgmt 

I'm very unfamiliar with btmgmt, how do I specify that I want LE 2M PHY whenever possible?

If I run: btmgmt phy

I get the available PHYs which incudes the LE2MTX and LE2MRX (which I am after).

Supported phys: BR1M1SLOT BR1M3SLOT BR1M5SLOT EDR2M1SLOT EDR2M3SLOT EDR2M5SLOT EDR3M1SLOT EDR3M3SLOT EDR3M5SLOT LE1MTX LE1MRX LE2MTX LE2MRX 
Configurable phys: BR1M3SLOT BR1M5SLOT EDR2M1SLOT EDR2M3SLOT EDR2M5SLOT EDR3M1SLOT EDR3M3SLOT EDR3M5SLOT LE2MTX LE2MRX 
Selected phys: BR1M1SLOT BR1M3SLOT BR1M5SLOT EDR2M1SLOT EDR2M3SLOT EDR2M5SLOT EDR3M1SLOT EDR3M3SLOT EDR3M5SLOT LE2MTX LE2MRX 

These can also be seen in btmon:

      Get PHY Configuration (0x0044) plen 12
        Status: Success (0x00)
        Supported PHYs: 0x1fff
          BR 1M 1SLOT
          BR 1M 3SLOT
          BR 1M 5SLOT
          EDR 2M 1SLOT
          EDR 2M 3SLOT
          EDR 2M 5SLOT
          EDR 3M 1SLOT
          EDR 3M 3SLOT
          EDR 3M 5SLOT
          LE 1M TX
          LE 1M RX
          LE 2M TX
          LE 2M RX
        Configurable PHYs: 0x19fe
          BR 1M 3SLOT
          BR 1M 5SLOT
          EDR 2M 1SLOT
          EDR 2M 3SLOT
          EDR 2M 5SLOT
          EDR 3M 1SLOT
          EDR 3M 3SLOT
          EDR 3M 5SLOT
          LE 2M TX
          LE 2M RX
        Selected PHYs: 0x19ff
          BR 1M 1SLOT
          BR 1M 3SLOT
          BR 1M 5SLOT
          EDR 2M 1SLOT
          EDR 2M 3SLOT
          EDR 2M 5SLOT
          EDR 3M 1SLOT
          EDR 3M 3SLOT
          EDR 3M 5SLOT
          LE 2M TX
          LE 2M RX
1

There are 1 best solutions below

0
Christian Eggers On

You cannot disable PHYs which are not configurable. You have to include at least BR1M1SLOT, LE1MTX and LE1MRX in the list of PHYs. So, calling the following should work:

btmgmt phy BR1M1SLOT LE1MTX LE1MRX LE2MTX LE2MRX

The list of configurable PHYs is hard-coded within the Linux kernel (as in 5.15.141):

static u32 get_configurable_phys(struct hci_dev *hdev)
{
    return (get_supported_phys(hdev) & ~MGMT_PHY_BR_1M_1SLOT &
        ~MGMT_PHY_LE_1M_TX & ~MGMT_PHY_LE_1M_RX);
}

Please note that btmgmt phy causes setting the default PHY (Bluetooth Core v5.3, section 7.8.48 – LE Set Default PHY command). This is the list of preferred PHYs which is used for new connections. As it is not possible to only specify the BLE 2M PHYs here, I cannot tell whether the command above increases the chance that actually the BLE 2M PHYs will be used.

The Bluetooth Core v5.3 specification has another chapter (7.8.49 – LE Set PHY command) to set the PHY(s) of an active connection. But this HCI command is not implemented in btmgmt nor in the Linux kernel. A patch series which calls the LE Set PHY command for the underlying LE connection of a socket (via setsockopt) has been rejected.

As a last resort, you could try to force the PHY via hcitool:

hcitool cmd 0x08 0x0031 0x00 0x02 0x02

This sets the default PHY for new LE connections to BLE 2M (without BLE 1M). But I haven't tested whether this finally gives the desired result.