Skip to content

Commit

Permalink
Bluetooth: SDP: Attempt reuse existing SDP client session
Browse files Browse the repository at this point in the history
Adds validation check when 'sdp discovery' API is to be called
by client, to reuse existing connection if valid or initiate new one
if posssible to set SDP L2CAP link to remote.

Change-Id: I47ce33cb5e95cf2616f9b23712641b912ce40f37
Signed-off-by: Arkadiusz Lichwa <[email protected]>
  • Loading branch information
xpuarli authored and Johan Hedberg committed Dec 24, 2016
1 parent 71fdc90 commit 3cbce90
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion subsys/bluetooth/host/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@ int bt_sdp_register_service(struct bt_sdp_record *service)
return 0;
}

/* Make sure whether there's existing valid session that can be still used */
static struct bt_sdp_client *get_client_session(struct bt_conn *conn)
{
int i;

for (i = 0; i < ARRAY_SIZE(bt_sdp_client_pool); i++) {
if (bt_sdp_client_pool[i].chan.chan.conn == conn) {
return &bt_sdp_client_pool[i];
}
}

return NULL;
}

static int sdp_client_chan_connect(struct bt_sdp_client *session)
{
return bt_l2cap_br_chan_connect(session->chan.chan.conn,
Expand Down Expand Up @@ -372,5 +386,16 @@ static int sdp_client_connect(struct bt_conn *conn)
int bt_sdp_discover(struct bt_conn *conn,
const struct bt_sdp_discover_params *params)
{
return sdp_client_connect(conn);
struct bt_sdp_client *session;
int err;

session = get_client_session(conn);
if (!session) {
err = sdp_client_connect(conn);
if (err) {
return err;
}
}

return 0;
}

0 comments on commit 3cbce90

Please sign in to comment.