main.conf: GATT.ExchangeMTU
Hi,
for testing purposes, I tried to lower GATT's ExchangeMTU in main.conf:
Quoted 4 lines
# Exchange MTU size.
# Possible values: 23-517
# Defaults to 517
ExchangeMTU = 23
Unfortunately, bluetoothd doesn't show my adapter anymore after this change:
Quoted 3 lines
daemon.err bluetoothd[450]: /usr/src/debug/bluez5/5.82/src/gatt-database.c:btd_gatt_database_new() Failed to start listening:
setsockopt(L2CAP_OPTIONS): Invalid argument (22) daemon.err bluetoothd[450]: Failed to create GATT database for adapter
daemon.err bluetoothd[450]: Unable to register new adapter
The first error message seems to come from btd_gatt_database_new() [1].
...
bredr:
/* BR/EDR socket */
database->bredr_io = bt_io_listen(connect_cb, NULL, NULL, NULL, &gerr,
BT_IO_OPT_SOURCE_BDADDR, addr,
BT_IO_OPT_PSM, BT_ATT_PSM,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
BT_IO_OPT_MTU, btd_opts.gatt_mtu,
BT_IO_OPT_INVALID);
if (database->bredr_io == NULL) {
error("Failed to start listening: %s", gerr->message);
g_error_free(gerr);
goto fail;
}...
Interestingly, the ExchangeMTU value from main.conf seems not to be used when creating the 'le_io' socket (isn't this the most important one?), so I guess that the error message is raised when creating the 'bredr_io' socket. The kernel has different allowed ranges for the MTU, depending on the L2CAP CID value:
static bool l2cap_valid_mtu(struct l2cap_chan *chan, u16 mtu)
{
switch (chan->scid) {
case L2CAP_CID_ATT:
if (mtu && mtu < L2CAP_LE_MIN_MTU)
return false;
break;
default:
if (mtu && mtu < L2CAP_DEFAULT_MIN_MTU)
return false;
}
return true;
}As the 'bredr_io' (and the 'eatt_io') sockets are not created with the L2CAP_CID_ATT cid, the default branch is taken here which imposes a minimum MTU value of 48.
Questions:
1. Is it correct that the value of ExchangeMTU isn't used for the LE socket?
2. Should the kernel allow MTU values such as 23 for all (GATT) sockets?
3. Where/how should this be fixed (kernel / bluetoothd / main.conf)?
regards,
Christian
[1] https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/gatt-database.c#n4103
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/bluetooth/l2cap_sock.c#n709
Luiz Augusto von Dentz
maintainerHi Christian,
Quoted 56 lines · Christian Eggers
Hi,
for testing purposes, I tried to lower GATT's ExchangeMTU in main.conf:
Quoted 4 lines
# Exchange MTU size.
# Possible values: 23-517
# Defaults to 517
ExchangeMTU = 23Unfortunately, bluetoothd doesn't show my adapter anymore after this change:
Quoted 3 lines
daemon.err bluetoothd[450]: /usr/src/debug/bluez5/5.82/src/gatt-database.c:btd_gatt_database_new() Failed to start listening:
setsockopt(L2CAP_OPTIONS): Invalid argument (22) daemon.err bluetoothd[450]: Failed to create GATT database for adapter
daemon.err bluetoothd[450]: Unable to register new adapterThe first error message seems to come from
btd_gatt_database_new()[1]....
bredr:/* BR/EDR socket */ database->bredr_io = bt_io_listen(connect_cb, NULL, NULL, NULL, &gerr, BT_IO_OPT_SOURCE_BDADDR, addr, BT_IO_OPT_PSM, BT_ATT_PSM, BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM, BT_IO_OPT_MTU, btd_opts.gatt_mtu, BT_IO_OPT_INVALID); if (database->bredr_io == NULL) { error("Failed to start listening: %s", gerr->message); g_error_free(gerr); goto fail; }...
Interestingly, the ExchangeMTU value from main.conf seems not to be used when creating the '
le_io' socket (isn't this the most important one?), so I guess that the error message is raised when creating the 'bredr_io' socket. The kernel has different allowed ranges for the MTU, depending on the L2CAP CID value:static bool
l2cap_valid_mtu(struct l2cap_chan *chan, u16 mtu){ switch (chan->scid) { case L2CAP_CID_ATT: if (mtu && mtu < L2CAP_LE_MIN_MTU) return false; break; default: if (mtu && mtu < L2CAP_DEFAULT_MIN_MTU) return false; } return true; }
Quoted 3 lines
As the '
bredr_io' (and the 'eatt_io') sockets are not created with theL2CAP_CID_ATTcid, the default branch is taken here which imposes a minimum MTU value of 48.
Yeah, you can't go with 23 for classic, perhaps we could split the setting for setting it or something like it.
Quoted 2 lines
Questions:
1. Is it correct that the value of ExchangeMTU isn't used for the LE socket?
It is used, it is not used in the socket though since it is a fixed CID the MTU is not configurable, thus you need to use ATT to exchange the MTU.
Quoted 1 line
2. Should the kernel allow MTU values such as 23 for all (GATT) sockets?
Don't think that is an option for BR/EDR.
Quoted 1 line
3. Where/how should this be fixed (kernel / bluetoothd / main.conf)?
Well if you think you can do 23 for all sockets, you don't, but if you want just LE perhaps you should disable classic then? Otherwise we will need a different setting for ATT over Classic.
Quoted 10 lines
regards,
Christian[1] https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/gatt-database.c#n4103
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/bluetooth/l2cap_sock.c#n709
Signature · 1 line
Luiz Augusto von Dentz
Hi Luiz,
Quoted 3 lines · Luiz Augusto von Dentz
... but if you
want just LE perhaps you should disable classic then?
Do you mean setting "ControllerMode" to "le"? I already have this in my config. It seems that this has no effect when creating the GATT sockets...
Quoted 2 lines
Otherwise we
will need a different setting for ATT over Classic.
I only needed this because I wanted to test with MTU < 64 for Mesh provisioning via GATT. Setting ExchangeMTU = 48 is sufficient for this.
But I think that at least the documentation in main.conf should be updated.
Luiz Augusto von Dentz
maintainerHi Christian,
Quoted 10 lines · Christian Eggers
Hi Luiz,
Quoted 3 lines · Luiz Augusto von Dentz
... but if you
want just LE perhaps you should disable classic then?Do you mean setting "ControllerMode" to "le"? I already have this in my config. It seems that this has no effect when creating the GATT sockets...
Oh, looks like the BR/EDR socket was not made conditional to BR/EDR being enable, it should be fixed now:
https://github.com/bluez/bluez/commit/5e248deb85872a1031d2e18602ad04f39eae61d0
Quoted 35 lines
Quoted 2 lines
Otherwise we
will need a different setting for ATT over Classic.I only needed this because I wanted to test with MTU < 64 for Mesh provisioning via GATT. Setting ExchangeMTU = 48 is sufficient for this.
But I think that at least the documentation in main.conf should be updated.
_______________________________________________________
Christian
Eggers
Software Engineer
ARRI
Arnold & Richter Cine Technik GmbH & Co. Betriebs KG Arriweg 17,
83071
Stephanskirchen
www.arri.com+49 8036 3009-3118
[email protected]Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: München ‑ Registergericht: Amtsgericht München ‑ Handelsregisternummer: HRA 57918 Persönlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: München ‑ Registergericht: Amtsgericht München ‑ Handelsregisternummer: HRB 54477 Geschäftsführer: David Bermbach, Wolfgang Börsig, Christian Richter
Signature · 1 line
Luiz Augusto von Dentz