Bluetooth: SDP: Initial implementation of bt_sdp_discover API

Adds basic functionality to be able to trigger establishing outgoing
L2CAP channel to remote using as PSM SDP channel. The number of such
outgoing connections is limited by configured pool of connections.

Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>

Change-Id: Ie5428e5b1b5f5c57f473ee0adfd4621cd9fe6e3e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
This commit is contained in:
Arkadiusz Lichwa 2016-12-19 14:39:44 +01:00 committed by Johan Hedberg
commit b71e34da81

View file

@ -57,6 +57,14 @@ static struct bt_sdp bt_sdp_pool[CONFIG_BLUETOOTH_MAX_CONN];
NET_BUF_POOL_DEFINE(sdp_pool, CONFIG_BLUETOOTH_MAX_CONN,
BT_L2CAP_BUF_SIZE(SDP_MTU), BT_BUF_USER_DATA_MIN, NULL);
#define SDP_CLIENT_MTU 64
struct bt_sdp_client {
struct bt_l2cap_br_chan chan;
};
static struct bt_sdp_client bt_sdp_client_pool[CONFIG_BLUETOOTH_MAX_CONN];
/** @brief Callback for SDP connection
*
* Gets called when an SDP connection is established
@ -306,3 +314,37 @@ int bt_sdp_register_service(struct bt_sdp_record *service)
return 0;
}
static int sdp_client_chan_connect(struct bt_sdp_client *session)
{
return bt_l2cap_br_chan_connect(session->chan.chan.conn,
&session->chan.chan, SDP_PSM);
}
static int sdp_client_connect(struct bt_conn *conn)
{
int i;
for (i = 0; i < ARRAY_SIZE(bt_sdp_client_pool); i++) {
struct bt_sdp_client *session = &bt_sdp_client_pool[i];
if (session->chan.chan.conn) {
continue;
}
session->chan.chan.conn = conn;
session->chan.rx.mtu = SDP_CLIENT_MTU;
return sdp_client_chan_connect(session);
}
BT_ERR("No available SDP client context");
return -ENOMEM;
}
int bt_sdp_discover(struct bt_conn *conn,
const struct bt_sdp_discover_params *params)
{
return sdp_client_connect(conn);
}