From df1fd21892fe7620a38d694caec82d417e4e3d2e Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Thu, 19 Oct 2023 10:53:54 +0200 Subject: [PATCH] Bluetooth: audio: has: Truncate Control Point notifications to ATT MTU This will truncate ATT notifications/indications if exceed ATT MTU size. It is up to the client to exchange MTU. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/has.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/subsys/bluetooth/audio/has.c b/subsys/bluetooth/audio/has.c index ceb273c5248..eca2761e43f 100644 --- a/subsys/bluetooth/audio/has.c +++ b/subsys/bluetooth/audio/has.c @@ -727,6 +727,15 @@ static void control_point_ind_complete(struct bt_conn *conn, static int control_point_send(struct has_client *client, struct net_buf_simple *buf) { + const uint16_t mtu_size = bt_gatt_get_mtu(client->conn); + /* PDU structure is [Opcode (1)] [Handle (2)] [...] */ + const uint16_t pdu_size = 3 + buf->len; + + if (mtu_size < pdu_size) { + LOG_WRN("Sending truncated control point PDU %d < %d", mtu_size, pdu_size); + buf->len -= (pdu_size - mtu_size); + } + #if defined(CONFIG_BT_HAS_PRESET_CONTROL_POINT_NOTIFIABLE) if (bt_eatt_count(client->conn) > 0 && bt_gatt_is_subscribed(client->conn, preset_control_point_attr, BT_GATT_CCC_NOTIFY)) {