bluez / bluez

Main BlueZ tree
https://bluez.github.io/bluez/
GNU General Public License v2.0
746 stars 273 forks source link

Unable to respond to or initiate Connection Parameter Update Procedure as a Central #717

Open 0xff07 opened 9 months ago

0xff07 commented 9 months ago

It seems that there's no way to respond to invalid L2CAP connection parameters as a Central responder, nor can it initiate Connection Parameter Update Procedure. The constraints can be set in the following files of debugfs:

  1. /sys/kernel/debug/bluetooth/hci0/conn_min_interval
  2. /sys/kernel/debug/bluetooth/hci0/conn_max_interval

But the comparison against those 2 values doesn's seem happen when Linux is a Central. In particular, in the l2cap_conn_param_update_req() of the net/bluetooth/l2cap_core.c [1].

I can see this functionality had been included in this commit of Linux kernel:

Bluetooth: validate BLE connection interval updates [2] (c49a8682fc5d298d44e8d911f4fa14690ea9485e)

but was reverted in this commit due to regression concerns.

Revert "Bluetooth: validate BLE connection interval updates" [3] (68d19d7d995759b96169da5aac313363f92a9075)

I'd like to understand if there's any other way to do this, or an further discussion regarding this? Thank you.

[1] https://elixir.bootlin.com/linux/latest/source/net/bluetooth/l2cap_core.c#L5616 [2] https://lore.kernel.org/linux-bluetooth/20190815104419.161177fa@kemnade.info/t/ [3] https://lore.kernel.org/lkml/20191003154253.184041960@linuxfoundation.org/

Vudentz commented 9 months ago

@0xff07 You can initiate the intervals by setting it via main.conf:

https://github.com/bluez/bluez/blob/master/src/main.conf#L213

The problem is that if the remote end attempts to update we store its value then the value of main.conf are superceeded, perhaps you are after rejecting interval updates from the peripheral? This sort of interface is not available right now, usually the peripheral knows best what interval works for them as they might have some limitation in term of battery, etc, that said sometimes the central is connected to multiple devices and changing the interval may result in collisions at link-layer.

0xff07 commented 9 months ago

Thank you. Now I see that rejection may not work at least in kernel. I can also confirm that setting parameters in main.conf works, although the parameters seems to be set by in an "LE Extended Create Connection" HCI command, instead of using the L2CAP Connection Parameter Update Procedure:

< HCI Command: LE Extended Create Connection (0x08|0x0043) plen 26                                                                                                                       #8 [hci0] 4.136896
        Filter policy: Accept list is not used (0x00)
        Own address type: Public (0x00)
        Peer address type: Public (0x00)
        Peer address: MA:CA:DD:RE:SS (OUI C0-07-E8)
        Initiating PHYs: 0x01
        Entry 0: LE 1M
          Scan interval: 60.000 msec (0x0060)
          Scan window: 60.000 msec (0x0060)
          Min connection interval: 62.50 msec (0x0032)
          Max connection interval: 87.50 msec (0x0046)
          Connection latency: 1 (0x0001)
          Supervision timeout: 5000 msec (0x01f4)
          Min connection length: 0.000 msec (0x0000)
          Max connection length: 0.000 msec (0x0000)
> HCI Event: Command Status (0x0f) plen 4                                                                                                                                                #9 [hci0] 4.141766
      LE Extended Create Connection (0x08|0x0043) ncmd 1
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 31                                                                                                                                               #10 [hci0] 4.455103
      LE Enhanced Connection Complete (0x0a)
        Status: Success (0x00)
        Handle: 10
        Role: Central (0x00)
        Peer address type: Public (0x00)
        Peer address:  MA:CA:DD:RE:SS  (OUI C0-07-E8)
        Local resolvable private address: 00:00:00:00:00:00 (Non-Resolvable)
        Peer resolvable private address: 00:00:00:00:00:00 (Non-Resolvable)
        Connection interval: 82.50 msec (0x0042)
        Connection latency: 1 (0x0001)
        Supervision timeout: 5000 msec (0x01f4)
        Central clock accuracy: 0x00
@ MGMT Event: Device Connected (0x000b) plen 34                                                                                                                                    {0x0002} [hci0] 4.455163
        LE Address:  MA:CA:DD:RE:SS  (OUI C0-07-E8)
        Flags: 0x00000008
          Connection Locally Initiated
        Data length: 21
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        16-bit Service UUIDs (partial): 1 entry
          Generic Access Profile (0x1800)
        Name (complete): PTS-GAP-2712
@ MGMT Event: Device Connected (0x000b) plen 34                                                                                                                                    {0x0001} [hci0] 4.455163
        LE Address: MA:CA:DD:RE:SS  (OUI C0-07-E8)
        Flags: 0x00000008
          Connection Locally Initiated
        Data length: 21
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        16-bit Service UUIDs (partial): 1 entry
          Generic Access Profile (0x1800)
        Name (complete): PTS-GAP-2712

I'd like to know further on:

  1. would it be possible to initiate it using the L2CAP Connection Parameter Update Procedure?
  2. Is it possible to initiate the Connection Parameter Update Procedure after a connection has been established?