* [PATCH] Populate adapter services list
@ 2010-11-30 9:51 Daniel Örstadius
2010-11-30 11:33 ` Daniel Örstadius
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Örstadius @ 2010-11-30 9:51 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 46 bytes --]
Attaching patch proposal for review.
/Daniel
[-- Attachment #2: 0001-Populate-adapter-services-list.patch --]
[-- Type: text/x-patch, Size: 2841 bytes --]
From aa9b2a347d19f50575e6b2864f503e9d4540369c Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@nokia.com>
Date: Tue, 30 Nov 2010 11:42:08 +0200
Subject: [PATCH] Populate adapter services list
In case that service records have been added to bluetoothd before
a new adapter is registered, the added records which are shared by
all adapters (indicated by having an address set to BDADDR_ANY)
need to be added to the services list of the new adapter. This
patch adds a function for this on adapter initialization.
The issue could be reproduced by running bluetoothd and obexd on a
PC and briefly removing the BT dongle. The service records from
obexd would not be present in the adapter's local list (which is
used to set the class of device).
---
src/adapter.c | 1 +
src/sdpd-database.c | 43 +++++++++++++++++++++++++++++++++++++++++++
src/sdpd.h | 2 ++
3 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 999f369..7d05098 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2319,6 +2319,7 @@ proceed:
return err;
if (adapter->initialized == FALSE) {
+ sdp_populate_services(&adapter->bdaddr);
load_drivers(adapter);
clear_blocked(adapter);
load_devices(adapter);
diff --git a/src/sdpd-database.c b/src/sdpd-database.c
index da3bc7d..111371d 100644
--- a/src/sdpd-database.c
+++ b/src/sdpd-database.c
@@ -81,6 +81,19 @@ static int access_sort(const void *r1, const void *r2)
return rec1->handle - rec2->handle;
}
+static int find_device(const void *r1, const void *r2)
+{
+ const sdp_access_t *rec1 = r1;
+ const sdp_access_t *rec2 = r2;
+
+ if (!rec1 || !rec2) {
+ error("NULL RECORD LIST FATAL");
+ return -1;
+ }
+
+ return bacmp(&rec1->device, &rec2->device);
+}
+
static void access_free(void *p)
{
free(p);
@@ -306,3 +319,33 @@ uint32_t sdp_next_handle(void)
return handle;
}
+
+void sdp_populate_services(bdaddr_t *device)
+{
+ sdp_record_t *rec;
+ sdp_list_t *p;
+ sdp_access_t ref_adr;
+ sdp_access_t *access;
+
+ SDPDBG("");
+
+ if (!access_db)
+ return;
+
+ bacpy(&ref_adr.device, BDADDR_ANY);
+ p = sdp_list_find(access_db, &ref_adr, find_device);
+
+ while (p) {
+ access = (sdp_access_t*) (p->data);
+
+ rec = sdp_record_find(access->handle);
+
+ if (rec) {
+ SDPDBG("adding record with handle %d", access->handle);
+ adapter_service_insert(device, rec);
+ }
+
+ p = p->next ?
+ (sdp_list_find(p->next, &ref_adr, find_device)) : NULL;
+ }
+}
diff --git a/src/sdpd.h b/src/sdpd.h
index f8e6ee7..b69034a 100644
--- a/src/sdpd.h
+++ b/src/sdpd.h
@@ -106,3 +106,5 @@ int remove_record_from_server(uint32_t handle);
void create_ext_inquiry_response(const char *name,
int8_t tx_power, sdp_list_t *services,
uint8_t *data);
+
+void sdp_populate_services(bdaddr_t *device);
--
1.6.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] Populate adapter services list
2010-11-30 9:51 [PATCH] Populate adapter services list Daniel Örstadius
@ 2010-11-30 11:33 ` Daniel Örstadius
2010-11-30 11:50 ` Johan Hedberg
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Örstadius @ 2010-11-30 11:33 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 58 bytes --]
Updated patch after offline feedback from Johan.
/Daniel
[-- Attachment #2: 0001-Initialize-adapter-services-list.patch --]
[-- Type: text/x-patch, Size: 2248 bytes --]
From 42edf146231aa053bbcc97d80fd9dd3aa3f247ec Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@nokia.com>
Date: Tue, 30 Nov 2010 13:27:57 +0200
Subject: [PATCH] Initialize adapter services list
In case service records have been added to bluetoothd before a new
adapter is registered, the records which are shared by all adapters
(indicated by having the address set to BDADDR_ANY) need to be added
to the services list of the new adapter. This patch adds a function
for this on adapter initialization.
The issue could be reproduced by running bluetoothd and obexd on a
PC and briefly removing the BT dongle. The service records from
obexd would not be present in the adapter's local list (which is
used to set the class of device).
---
src/adapter.c | 1 +
src/sdpd-database.c | 24 ++++++++++++++++++++++++
src/sdpd.h | 2 ++
3 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 999f369..62afc0c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2319,6 +2319,7 @@ proceed:
return err;
if (adapter->initialized == FALSE) {
+ sdp_init_services_list(&adapter->bdaddr);
load_drivers(adapter);
clear_blocked(adapter);
load_devices(adapter);
diff --git a/src/sdpd-database.c b/src/sdpd-database.c
index da3bc7d..f3538ae 100644
--- a/src/sdpd-database.c
+++ b/src/sdpd-database.c
@@ -306,3 +306,27 @@ uint32_t sdp_next_handle(void)
return handle;
}
+
+void sdp_init_services_list(bdaddr_t *device)
+{
+ sdp_list_t *p;
+
+ SDPDBG("");
+
+ for (p = access_db; p != NULL; p = p->next) {
+ sdp_record_t *rec;
+ sdp_access_t *access = p->data;
+
+ if (bacmp(BDADDR_ANY, &access->device))
+ continue;
+
+ rec = sdp_record_find(access->handle);
+
+ if (rec == NULL)
+ continue;
+
+ SDPDBG("adding record with handle %x", access->handle);
+
+ adapter_service_insert(device, rec);
+ }
+}
diff --git a/src/sdpd.h b/src/sdpd.h
index f8e6ee7..0e3dddf 100644
--- a/src/sdpd.h
+++ b/src/sdpd.h
@@ -106,3 +106,5 @@ int remove_record_from_server(uint32_t handle);
void create_ext_inquiry_response(const char *name,
int8_t tx_power, sdp_list_t *services,
uint8_t *data);
+
+void sdp_init_services_list(bdaddr_t *device);
--
1.6.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] Populate adapter services list
2010-11-30 11:33 ` Daniel Örstadius
@ 2010-11-30 11:50 ` Johan Hedberg
0 siblings, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2010-11-30 11:50 UTC (permalink / raw)
To: Daniel Örstadius; +Cc: linux-bluetooth
Hi Daniel,
On Tue, Nov 30, 2010, Daniel Örstadius wrote:
> In case service records have been added to bluetoothd before a new
> adapter is registered, the records which are shared by all adapters
> (indicated by having the address set to BDADDR_ANY) need to be added
> to the services list of the new adapter. This patch adds a function
> for this on adapter initialization.
>
> The issue could be reproduced by running bluetoothd and obexd on a
> PC and briefly removing the BT dongle. The service records from
> obexd would not be present in the adapter's local list (which is
> used to set the class of device).
> ---
> src/adapter.c | 1 +
> src/sdpd-database.c | 24 ++++++++++++++++++++++++
> src/sdpd.h | 2 ++
> 3 files changed, 27 insertions(+), 0 deletions(-)
Thanks. Pushed upstream after a few minor cosmetic changes.
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-11-30 11:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-30 9:51 [PATCH] Populate adapter services list Daniel Örstadius
2010-11-30 11:33 ` Daniel Örstadius
2010-11-30 11:50 ` Johan Hedberg
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).