From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 1/4] shared/mgmt: Set MTU to UINT16_MAX
Date: Wed, 22 Sep 2021 14:33:59 -0700 [thread overview]
Message-ID: <20210922213402.1978215-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This sets MTU of MGMT socket to UINT16_MAX since some commands may
require more than the default size (e.g. Load LTKs).
Fixes: https://github.com/bluez/bluez/issues/201
---
src/shared/mgmt.c | 46 ++++++++++++++++++++++++++++++++++++++++------
1 file changed, 40 insertions(+), 6 deletions(-)
diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index b869fa6ef..cec8993e7 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
@@ -42,6 +42,7 @@ struct mgmt {
bool in_notify;
void *buf;
uint16_t len;
+ uint16_t mtu;
mgmt_debug_func_t debug_callback;
mgmt_destroy_func_t debug_destroy;
void *debug_data;
@@ -380,6 +381,32 @@ static bool can_read_data(struct io *io, void *user_data)
return true;
}
+static void mgmt_set_mtu(struct mgmt *mgmt)
+{
+ socklen_t len = 0;
+
+ /* Check if kernel support BT_SNDMTU to read the current MTU set */
+ if (getsockopt(mgmt->fd, SOL_BLUETOOTH, BT_SNDMTU, &mgmt->mtu,
+ &len) < 0) {
+ /* If BT_SNDMTU is not supported then MTU cannot be changed and
+ * MTU is fixed to HCI_MAX_ACL_SIZE.
+ */
+ mgmt->mtu = HCI_MAX_ACL_SIZE;
+ return;
+ }
+
+ if (mgmt->mtu < UINT16_MAX) {
+ uint16_t mtu = UINT16_MAX;
+
+ /* Try increasing the MTU since some commands may go
+ * over HCI_MAX_ACL_SIZE (1024)
+ */
+ if (!setsockopt(mgmt->fd, SOL_BLUETOOTH, BT_SNDMTU, &mtu,
+ sizeof(mtu)))
+ mgmt->mtu = mtu;
+ }
+}
+
struct mgmt *mgmt_new(int fd)
{
struct mgmt *mgmt;
@@ -423,6 +450,8 @@ struct mgmt *mgmt_new(int fd)
mgmt->writer_active = false;
+ mgmt_set_mtu(mgmt);
+
return mgmt_ref(mgmt);
}
@@ -534,9 +563,9 @@ bool mgmt_set_close_on_unref(struct mgmt *mgmt, bool do_close)
return true;
}
-static struct mgmt_request *create_request(uint16_t opcode, uint16_t index,
- uint16_t length, const void *param,
- mgmt_request_func_t callback,
+static struct mgmt_request *create_request(struct mgmt *mgmt, uint16_t opcode,
+ uint16_t index, uint16_t length,
+ const void *param, mgmt_request_func_t callback,
void *user_data, mgmt_destroy_func_t destroy)
{
struct mgmt_request *request;
@@ -548,6 +577,11 @@ static struct mgmt_request *create_request(uint16_t opcode, uint16_t index,
if (length > 0 && !param)
return NULL;
+ if (length > mgmt->mtu) {
+ printf("length %u > %u mgmt->mtu", length, mgmt->mtu);
+ return NULL;
+ }
+
request = new0(struct mgmt_request, 1);
request->len = length + MGMT_HDR_SIZE;
request->buf = malloc(request->len);
@@ -711,7 +745,7 @@ unsigned int mgmt_send(struct mgmt *mgmt, uint16_t opcode, uint16_t index,
if (!mgmt)
return 0;
- request = create_request(opcode, index, length, param,
+ request = create_request(mgmt, opcode, index, length, param,
callback, user_data, destroy);
if (!request)
return 0;
@@ -742,7 +776,7 @@ unsigned int mgmt_send_nowait(struct mgmt *mgmt, uint16_t opcode, uint16_t index
if (!mgmt)
return 0;
- request = create_request(opcode, index, length, param,
+ request = create_request(mgmt, opcode, index, length, param,
callback, user_data, destroy);
if (!request)
return 0;
@@ -768,7 +802,7 @@ unsigned int mgmt_reply(struct mgmt *mgmt, uint16_t opcode, uint16_t index,
if (!mgmt)
return 0;
- request = create_request(opcode, index, length, param,
+ request = create_request(mgmt, opcode, index, length, param,
callback, user_data, destroy);
if (!request)
return 0;
--
2.31.1
next reply other threads:[~2021-09-22 21:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-22 21:33 Luiz Augusto von Dentz [this message]
2021-09-22 21:34 ` [PATCH BlueZ 2/4] lib: Fix HCI_MAX_ACL_SIZE Luiz Augusto von Dentz
2021-09-22 21:34 ` [PATCH BlueZ 3/4] shared/mgmt: Add mgmt_get_mtu Luiz Augusto von Dentz
2021-09-22 21:34 ` [PATCH BlueZ 4/4] adapter: Truncate number of LTKs loaded if over MGMT MTU Luiz Augusto von Dentz
2021-09-22 21:55 ` [BlueZ,1/4] shared/mgmt: Set MTU to UINT16_MAX bluez.test.bot
2021-09-22 22:35 ` bluez.test.bot
2021-09-23 21:25 ` Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210922213402.1978215-1-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox