gatt: Make ATT MTU configurable in main.conf
authorDavid Krauser <david@krauser.org>
Mon, 9 Jul 2018 16:27:20 +0000 (12:27 -0400)
committerhimanshu <h.himanshu@samsung.com>
Tue, 14 Jan 2020 08:53:35 +0000 (14:23 +0530)
This adds a new entry to GATT group called ExchangeMTU.

Change-Id: Ia026190e18bc759cc565475e629143307e231413
Signed-off-by: himanshu <h.himanshu@samsung.com>
src/device.c
src/gatt-database.c
src/hcid.h
src/main.c
src/main.conf

index 63f5a62..fbf2bcf 100644 (file)
@@ -7322,7 +7322,7 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io)
        }
 #endif
 
-       dev->att_mtu = MIN(mtu, BT_ATT_MAX_LE_MTU);
+       dev->att_mtu = MIN(mtu, main_opts.gatt_mtu);
        attrib = g_attrib_new(io,
                        cid == ATT_CID ? BT_ATT_DEFAULT_LE_MTU : dev->att_mtu,
                        false);
index 98c0b32..ea60c9a 100644 (file)
@@ -40,6 +40,7 @@
 #include "src/shared/gatt-server.h"
 #include "log.h"
 #include "error.h"
+#include "hcid.h"
 #include "adapter.h"
 #include "device.h"
 #include "gatt-database.h"
@@ -3871,6 +3872,7 @@ struct btd_gatt_database *btd_gatt_database_new(struct btd_adapter *adapter)
                                        BT_IO_OPT_SOURCE_BDADDR, addr,
                                        BT_IO_OPT_PSM, ATT_PSM,
                                        BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+                                       BT_IO_OPT_MTU, main_opts.gatt_mtu,
                                        BT_IO_OPT_INVALID);
        if (database->l2cap_io == NULL) {
                error("Failed to start listening: %s", gerr->message);
index 9243285..c4251eb 100755 (executable)
@@ -59,6 +59,7 @@ struct main_opts {
 
        bt_mode_t       mode;
        bt_gatt_cache_t gatt_cache;
+       uint16_t        gatt_mtu;
 
        uint8_t         min_enc_key_size;
 };
index 407cfff..b21f50a 100755 (executable)
@@ -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"
@@ -109,6 +110,7 @@ static const char *policy_options[] = {
 static const char *gatt_options[] = {
        "Cache",
        "MinEncKeySize",
+       "ExchangeMTU",
        NULL
 };
 
@@ -450,6 +452,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", "ExchangeMTU", &err);
+       if (err) {
+               DBG("%s", err->message);
+               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("ExchangeMTU=%d", val);
+               main_opts.gatt_mtu = val;
+       }
 }
 
 static void init_defaults(void)
@@ -478,6 +492,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_mtu = BT_ATT_MAX_LE_MTU;
 #endif
 }
 
index de18a58..ff0b879 100755 (executable)
 # Defaults to 0
 # MinEncKeySize = 0
 
+# Exchange MTU size.
+# Possible values: 23-517
+# Defaults to 517
+#ExchangeMTU = 517
+
 [Policy]
 #
 # The ReconnectUUIDs defines the set of remote services that should try