From: "Frédéric Danis" <frederic.danis@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH] sdp: Prevent duplicate records registration
Date: Wed, 20 Jun 2012 11:02:01 +0200 [thread overview]
Message-ID: <1340182921-12448-1-git-send-email-frederic.danis@linux.intel.com> (raw)
Check if a record with same UUID and protocol descriptor already exists
before adding new record to server
---
When BlueZ is built with --enable-pnat option, it provides DUN support on RFComm
port 1.
When current version of oFono is started, it also provides DUN support on same
port.
So, we get to 2 SDP records for same UUID and RFComm port.
This patch prevents this.
src/sdpd-service.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index 39e05ab..9e8b90c 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -235,6 +235,9 @@ int add_record_to_server(const bdaddr_t *src, sdp_record_t *rec)
{
sdp_data_t *data;
sdp_list_t *pattern;
+ sdp_list_t *record;
+ sdp_list_t *protos;
+ int port = -1, psm = -1;
if (rec->handle == 0xffffffff) {
rec->handle = sdp_next_handle();
@@ -245,6 +248,38 @@ int add_record_to_server(const bdaddr_t *src, sdp_record_t *rec)
return -EEXIST;
}
+ if (sdp_get_access_protos(rec, &protos) == 0) {
+ psm = sdp_get_proto_port(protos, L2CAP_UUID);
+ port = sdp_get_proto_port(protos, RFCOMM_UUID);
+
+ sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free, NULL);
+ sdp_list_free(protos, NULL);
+ }
+
+ for (record = sdp_get_record_list(); record; record = record->next) {
+ sdp_record_t *tmp = record->data;
+ int tmp_port = -1, tmp_psm = -1;
+
+ if (sdp_uuid_cmp(&tmp->svclass, &rec->svclass) != 0)
+ continue;
+
+ if (sdp_get_access_protos(tmp, &protos) == 0) {
+ tmp_psm = sdp_get_proto_port(protos, L2CAP_UUID);
+ tmp_port = sdp_get_proto_port(protos, RFCOMM_UUID);
+
+ sdp_list_foreach(protos,
+ (sdp_list_func_t) sdp_list_free, NULL);
+ sdp_list_free(protos, NULL);
+ }
+
+ if (psm != tmp_psm || port != tmp_port)
+ continue;
+
+ DBG("Record not added as handle 0x%05x already exists with "
+ "same uuid and protos", tmp->handle);
+ return -EEXIST;
+ }
+
DBG("Adding record with handle 0x%05x", rec->handle);
sdp_record_add(src, rec);
--
1.7.9.5
next reply other threads:[~2012-06-20 9:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-20 9:02 Frédéric Danis [this message]
2012-06-20 9:35 ` [PATCH] sdp: Prevent duplicate records registration Johan Hedberg
2012-06-20 13:09 ` Frederic Danis
2012-06-21 8:36 ` Luiz Augusto von Dentz
2012-06-29 13:35 ` Johan Hedberg
2012-06-29 13:43 ` Luiz Augusto von Dentz
2012-06-29 13:52 ` Frederic Danis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1340182921-12448-1-git-send-email-frederic.danis@linux.intel.com \
--to=frederic.danis@linux.intel.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).