From d460181eb0f452c2850c12ef451ad56da671aa6d Mon Sep 17 00:00:00 2001 From: Arkadiusz Lichwa Date: Tue, 20 Dec 2016 21:29:27 +0100 Subject: [PATCH] Bluetooth: SDP: Start receiving response data on SDP PSM Adds handler responsible for receiving SDP data on SDP client request. For now simple validation are done on SDP response header data. Jira: ZEP-1112 Change-Id: Ic6009030db34e26dfdbd57fa1b0a22f6e27b6a11 Signed-off-by: Arkadiusz Lichwa --- subsys/bluetooth/host/sdp.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/subsys/bluetooth/host/sdp.c b/subsys/bluetooth/host/sdp.c index 47072cd9285..3619cf2f28f 100644 --- a/subsys/bluetooth/host/sdp.c +++ b/subsys/bluetooth/host/sdp.c @@ -319,6 +319,33 @@ int bt_sdp_register_service(struct bt_sdp_record *service) return 0; } +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; + uint16_t len, tid; + + ARG_UNUSED(session); + + BT_DBG("session %p buf %p", session, buf); + + if (buf->len < sizeof(*hdr)) { + BT_ERR("Too small SDP PDU"); + return; + } + + len = sys_be16_to_cpu(hdr->param_len); + tid = sys_be16_to_cpu(hdr->tid); + net_buf_pull(buf, sizeof(*hdr)); + + BT_DBG("SDP PDU tid %u len %u", tid, len); + + if (buf->len != len) { + BT_ERR("SDP PDU length mismatch (%u != %u)", buf->len, len); + return; + } +} + static int sdp_client_chan_connect(struct bt_sdp_client *session) { return bt_l2cap_br_chan_connect(session->chan.chan.conn, @@ -350,6 +377,7 @@ static void sdp_client_disconnected(struct bt_l2cap_chan *chan) static struct bt_l2cap_chan_ops sdp_client_chan_ops = { .connected = sdp_client_connected, .disconnected = sdp_client_disconnected, + .recv = sdp_client_receive, }; static struct bt_sdp_client *sdp_client_new_session(struct bt_conn *conn)