diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index adf5581ebc4..142027775be 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -2417,11 +2417,9 @@ static void gatt_add_nfy_to_buf(struct net_buf *buf, { struct bt_att_notify_mult *nfy; - nfy = net_buf_add(buf, sizeof(*nfy)); + nfy = net_buf_add(buf, sizeof(*nfy) + params->len); nfy->handle = sys_cpu_to_le16(handle); nfy->len = sys_cpu_to_le16(params->len); - - net_buf_add(buf, params->len); (void)memcpy(nfy->value, params->data, params->len); } @@ -2532,10 +2530,8 @@ static int gatt_notify(struct bt_conn *conn, uint16_t handle, LOG_DBG("conn %p handle 0x%04x", conn, handle); - nfy = net_buf_add(buf, sizeof(*nfy)); + nfy = net_buf_add(buf, sizeof(*nfy) + params->len); nfy->handle = sys_cpu_to_le16(handle); - - net_buf_add(buf, params->len); memcpy(nfy->value, params->data, params->len); bt_att_set_tx_meta_data(buf, params->func, params->user_data, BT_ATT_CHAN_OPT(params)); @@ -2700,10 +2696,8 @@ static int gatt_indicate(struct bt_conn *conn, uint16_t handle, bt_att_set_tx_meta_data(buf, NULL, NULL, BT_ATT_CHAN_OPT(params)); - ind = net_buf_add(buf, sizeof(*ind)); + ind = net_buf_add(buf, sizeof(*ind) + params->len); ind->handle = sys_cpu_to_le16(handle); - - net_buf_add(buf, params->len); memcpy(ind->value, params->data, params->len); LOG_DBG("conn %p handle 0x%04x", conn, handle);