Skip to content

Commit

Permalink
Bluetooth: SDP: Allocate user delivered memory for resolved data
Browse files Browse the repository at this point in the history
Adds driven by user params buffer location to be populated by UUID
resolved data. Corresponding handlers responsible for connected and
disconnected states of L2CAP transport channel used by SDP PSM traffic
automatically allocates and unrefs such memory. Data receiving handler
performs buffer fill up.

Jira: ZEP-1112

Change-Id: I8aa97e6e69344dca0f241a4e9097acac75e14a7c
Signed-off-by: Arkadiusz Lichwa <[email protected]>
  • Loading branch information
xpuarli authored and Johan Hedberg committed Jan 5, 2017
1 parent 3304cbc commit c97220c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion subsys/bluetooth/host/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ struct bt_sdp_client {
const struct bt_sdp_discover_params *param;
/* PDU continuation state object */
struct bt_sdp_pdu_cstate cstate;
/* buffer for collecting record data */
struct net_buf *rec_buf;
};

static struct bt_sdp_client bt_sdp_client_pool[CONFIG_BLUETOOTH_MAX_CONN];
Expand Down Expand Up @@ -532,7 +534,7 @@ static void sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
goto iterate;
}

/* TO DO: fillup user buffer with record's data */
net_buf_add_mem(session->rec_buf, buf->data, frame_len);

net_buf_pull(buf, frame_len);

Expand All @@ -556,6 +558,8 @@ static void sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
net_buf_pull(buf, sizeof(cstate->length));

BT_DBG("UUID 0x%s resolved", bt_uuid_str(session->param->uuid));

/* TODO: Call user UUID callback with gathered SDP data */
iterate:
/* Get next UUID and start resolving it */
sdp_client_params_iterator(session);
Expand All @@ -572,12 +576,25 @@ static int sdp_client_chan_connect(struct bt_sdp_client *session)
&session->chan.chan, SDP_PSM);
}

static struct net_buf *sdp_client_alloc_buf(struct bt_l2cap_chan *chan)
{
struct bt_sdp_client *session = SDP_CLIENT_CHAN(chan);

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

session->param = GET_PARAM(sys_slist_peek_head(&session->reqs));

return net_buf_alloc(session->param->pool, K_FOREVER);
}

static void sdp_client_connected(struct bt_l2cap_chan *chan)
{
struct bt_sdp_client *session = SDP_CLIENT_CHAN(chan);

BT_DBG("session %p chan %p connected", session, chan);

session->rec_buf = chan->ops->alloc_buf(chan);

sdp_client_ssa_search(session);
}

Expand All @@ -587,6 +604,8 @@ static void sdp_client_disconnected(struct bt_l2cap_chan *chan)

BT_DBG("session %p chan %p disconnected", session, chan);

net_buf_unref(session->rec_buf);

/*
* Reset session excluding L2CAP channel member. Let's the channel
* resets autonomous.
Expand All @@ -598,6 +617,7 @@ static struct bt_l2cap_chan_ops sdp_client_chan_ops = {
.connected = sdp_client_connected,
.disconnected = sdp_client_disconnected,
.recv = sdp_client_receive,
.alloc_buf = sdp_client_alloc_buf,
};

static struct bt_sdp_client *sdp_client_new_session(struct bt_conn *conn)
Expand Down

0 comments on commit c97220c

Please sign in to comment.