From 3cbce9093602ea54fe6324a6f7dfd581d04359e4 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lichwa Date: Mon, 19 Dec 2016 21:27:54 +0100 Subject: [PATCH] Bluetooth: SDP: Attempt reuse existing SDP client session 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 --- subsys/bluetooth/host/sdp.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/sdp.c b/subsys/bluetooth/host/sdp.c index 7e7da4d2c7f456..6836df7a057ca1 100644 --- a/subsys/bluetooth/host/sdp.c +++ b/subsys/bluetooth/host/sdp.c @@ -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, @@ -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; }