Skip to content

Commit 3ac4f92

Browse files
lylezhu2012cfriedt
authored andcommitted
Bluetooth: Classic: OBEX: Optimize MOPL configuration
Set the MOPL of RX and TX to `BT_OBEX_MIN_MTU` when registering OBEX server. Set the TX MOPL to `BT_OBEX_MIN_MTU` when sending OBEX connection request. Check if the MOPL of client exceeds MTU of transport when server receives the connection request. Check if the MOPL of server exceeds MTU of transport when client receives the connection response. Signed-off-by: Lyle Zhu <[email protected]>
1 parent 26065ec commit 3ac4f92

File tree

1 file changed

+17
-5
lines changed
  • subsys/bluetooth/host/classic

1 file changed

+17
-5
lines changed

subsys/bluetooth/host/classic/obex.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ static int obex_server_connect(struct bt_obex_server *server, uint16_t len, stru
212212
LOG_DBG("version %u, flags %u, mopl %u", version, flags, mopl);
213213

214214
if (mopl < BT_OBEX_MIN_MTU) {
215-
LOG_WRN("Invalid MTU length (%d < %d)", mopl, BT_OBEX_MIN_MTU);
215+
LOG_WRN("Invalid MOPL (%d < %d)", mopl, BT_OBEX_MIN_MTU);
216+
rsp_code = BT_OBEX_RSP_CODE_PRECON_FAIL;
217+
goto failed;
218+
}
219+
220+
if (mopl > server->obex->tx.mtu) {
221+
LOG_WRN("MOPL exceeds MTU (%d > %d)", mopl, server->obex->tx.mtu);
216222
rsp_code = BT_OBEX_RSP_CODE_PRECON_FAIL;
217223
goto failed;
218224
}
@@ -949,9 +955,15 @@ static int obex_client_connect(struct bt_obex_client *client, uint8_t rsp_code,
949955
}
950956

951957
if (mopl < BT_OBEX_MIN_MTU) {
952-
LOG_WRN("Invalid MTU length (%d < %d)", mopl, BT_OBEX_MIN_MTU);
958+
LOG_WRN("Invalid MOPL (%d < %d)", mopl, BT_OBEX_MIN_MTU);
953959
goto failed;
954960
}
961+
962+
if (mopl > client->obex->tx.mtu) {
963+
LOG_WRN("MOPL exceeds MTU (%d > %d)", mopl, client->obex->tx.mtu);
964+
goto failed;
965+
}
966+
955967
client->tx.mopl = mopl;
956968

957969
atomic_set(&client->_state,
@@ -1374,9 +1386,9 @@ int bt_obex_server_register(struct bt_obex_server *server, const struct bt_uuid_
13741386
return -EINVAL;
13751387
}
13761388

1377-
server->rx.mopl = server->obex->rx.mtu;
1389+
server->rx.mopl = BT_OBEX_MIN_MTU;
13781390
/* Set MOPL of TX to MTU by default to avoid the OBEX connect rsp cannot be sent. */
1379-
server->tx.mopl = server->obex->tx.mtu;
1391+
server->tx.mopl = BT_OBEX_MIN_MTU;
13801392

13811393
server->uuid = uuid;
13821394

@@ -1485,7 +1497,7 @@ int bt_obex_connect(struct bt_obex_client *client, uint16_t mopl, struct net_buf
14851497

14861498
client->rx.mopl = mopl;
14871499
/* Set MOPL of TX to MTU by default to avoid the OBEX connect req cannot be sent. */
1488-
client->tx.mopl = client->obex->tx.mtu;
1500+
client->tx.mopl = BT_OBEX_MIN_MTU;
14891501
atomic_set(&client->_state, BT_OBEX_CONNECTING);
14901502

14911503
if (!sys_slist_find(&client->obex->_clients, &client->_node, NULL)) {

0 commit comments

Comments
 (0)