Skip to content

Commit

Permalink
Bluetooth: SDP: Check room needed against user allocated
Browse files Browse the repository at this point in the history
When getting very first SSA PDU response for given UUID we can extract
from it the counter telling us how much data will be delivered by server
to collect all complete response for given UUID. Let's use that
information to check if the room allocated by app is big enough for
collecting resolved data.

Jira: ZEP-1112

Change-Id: I91515da668d89e05755d64e427dee0936bf20323
Signed-off-by: Arkadiusz Lichwa <[email protected]>
  • Loading branch information
xpuarli authored and Johan Hedberg committed Jan 5, 2017
1 parent 7eacb04 commit 164aa00
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion subsys/bluetooth/host/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,54 @@ static void sdp_client_params_iterator(struct bt_sdp_client *session)
}
}

static uint16_t sdp_client_get_total(struct bt_sdp_client *session,
struct net_buf *buf, uint16_t *total)
{
uint16_t pulled;
uint8_t seq;

/*
* Pull value of total octets of all attributes available to be
* collected when response gets completed for given UUID. Such info can
* be get from the very first response frame after initial SSA request
* was sent. For subsequent calls related to the same SSA request input
* buf and in/out function parameters stays neutral.
*/
if (session->cstate.length == 0) {
seq = net_buf_pull_u8(buf);
pulled = 1;
switch (seq) {
case BT_SDP_SEQ8:
*total = net_buf_pull_u8(buf);
pulled += 1;
break;
case BT_SDP_SEQ16:
*total = net_buf_pull_be16(buf);
pulled += 2;
break;
default:
BT_WARN("Sequence type 0x%02x not handled", seq);
*total = 0;
break;
}

BT_DBG("Total %u octets of all attributes", *total);
} else {
pulled = 0;
*total = 0;
}

return pulled;
}

static void sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
{
struct bt_sdp_client *session = SDP_CLIENT_CHAN(chan);
struct bt_sdp_hdr *hdr = (void *)buf->data;
struct bt_sdp_pdu_cstate *cstate;
struct bt_conn *conn = session->chan.chan.conn;
uint16_t len, tid, frame_len;
uint16_t total;

BT_DBG("session %p buf %p", session, buf);

Expand Down Expand Up @@ -534,8 +575,15 @@ static void sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
goto iterate;
}

net_buf_add_mem(session->rec_buf, buf->data, frame_len);
/* Get total value of all attributes to be collected */
frame_len -= sdp_client_get_total(session, buf, &total);

if (total > net_buf_tailroom(session->rec_buf)) {
BT_WARN("Not enough room for getting records data");
goto iterate;
}

net_buf_add_mem(session->rec_buf, buf->data, frame_len);
net_buf_pull(buf, frame_len);

/*
Expand Down

0 comments on commit 164aa00

Please sign in to comment.