We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6d5dd34 commit f1be8afCopy full SHA for f1be8af
subsys/bluetooth/host/gatt.c
@@ -5261,10 +5261,18 @@ static int gatt_prepare_write(struct bt_conn *conn,
5261
struct bt_gatt_write_params *params)
5262
{
5263
uint16_t len, req_len;
5264
+ uint16_t mtu = bt_att_get_mtu(conn);
5265
5266
req_len = sizeof(struct bt_att_prepare_write_req);
5267
- len = bt_att_get_mtu(conn) - req_len - 1;
5268
+ /** MTU size is bigger than the ATT_PREPARE_WRITE_REQ header (5 bytes),
5269
+ * unless there's no connection.
5270
+ */
5271
+ if (mtu == 0) {
5272
+ return -ENOTCONN;
5273
+ }
5274
+
5275
+ len = mtu - req_len - 1;
5276
len = MIN(params->length, len);
5277
len += req_len;
5278
0 commit comments