Skip to content

Commit

Permalink
bluetooth: host: gatt: consolidate net_buf_add call
Browse files Browse the repository at this point in the history
Consolidate `net_buf_add` calls using known `param->len`
to streamline the codebase.

Signed-off-by: Pisit Sawangvonganan <[email protected]>
  • Loading branch information
ndrs-pst committed Dec 12, 2024
1 parent 7c4abb1 commit 3ddd5ee
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions subsys/bluetooth/host/gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3ddd5ee

Please sign in to comment.