On July 3, 2018 7:00 AM, Luiz Augusto von Dentz <luiz.dentz@xxxxxxxxx> wrote: > The MTU is negotiated automatically to the maximum value possible but > it doesn't really matter with WriteValue and ReadValue since they will > fragment and reassemble the data automatically, with Acquire* you will > get a file description which you can use to read or write. The characteristic that I've implemented pulls data from a buffer that is larger than the max value length, so I use the MTU size to determine how many bytes have been read. L2CAP CoC would probably be a better way to do this, but I'm working with platforms that don't support it, unfortunately :-( > may impact other profiles, so the only option I see here is to have a > setting in the main.conf saying what is the preferred MTU for > GATT/ATT [...] I like this idea. I've attached a patch below that implements this. Thanks for the suggestions - really helpful. - dk diff --git a/src/device.c b/src/device.c index 4f1af7012..75340cabe 100644 --- a/src/device.c +++ b/src/device.c @@ -4986,7 +4986,7 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io) } } - dev->att_mtu = MIN(mtu, BT_ATT_MAX_LE_MTU); + dev->att_mtu = MIN(mtu, main_opts.gatt_max_le_mtu); attrib = g_attrib_new(io, cid == ATT_CID ? BT_ATT_DEFAULT_LE_MTU : dev->att_mtu, false); diff --git a/src/hcid.h b/src/hcid.h index 2c2b89d9c..bcb077dde 100644 --- a/src/hcid.h +++ b/src/hcid.h @@ -54,6 +54,7 @@ struct main_opts { bt_mode_t mode; bt_gatt_cache_t gatt_cache; + uint16_t gatt_max_le_mtu; uint8_t min_enc_key_size; }; diff --git a/src/main.c b/src/main.c index 7e6af42cd..8ddd4875f 100644 --- a/src/main.c +++ b/src/main.c @@ -50,6 +50,7 @@ #include "log.h" #include "backtrace.h" +#include "shared/att-types.h" #include "lib/uuid.h" #include "hcid.h" #include "sdpd.h" @@ -104,6 +105,7 @@ static const char *policy_options[] = { static const char *gatt_options[] = { "Cache", "MinEncKeySize", + "MaxLeMtu", NULL }; @@ -419,6 +421,18 @@ static void parse_config(GKeyFile *config) if (val >=7 && val <= 16) main_opts.min_enc_key_size = val; } + + val = g_key_file_get_integer(config, "GATT", + "MaxLeMtu", &err); + if (err) { + g_clear_error(&err); + } else { + /* Ensure the mtu is within a valid range. */ + val = MIN(val, BT_ATT_MAX_LE_MTU); + val = MAX(val, BT_ATT_DEFAULT_LE_MTU); + DBG("gatt_max_le_mtu=%d", val); + main_opts.gatt_max_le_mtu = val; + } } static void init_defaults(void) @@ -442,6 +456,8 @@ static void init_defaults(void) main_opts.did_vendor = 0x1d6b; /* Linux Foundation */ main_opts.did_product = 0x0246; /* BlueZ */ main_opts.did_version = (major << 8 | minor); + + main_opts.gatt_max_le_mtu = BT_ATT_MAX_LE_MTU; } static void log_handler(const gchar *log_domain, GLogLevelFlags log_level, diff --git a/src/main.conf b/src/main.conf index cbae32ec5..a22d685b2 100644 --- a/src/main.conf +++ b/src/main.conf @@ -82,6 +82,11 @@ # Defaults to 0 # MinEncKeySize = 0 +# Maximum MTU size. +# Possible values: 23-517 +# Defaults to 517 +# MaxLeMtu = 517 + [Policy] # # The ReconnectUUIDs defines the set of remote services that should try -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html